title: Swift 3 Core Data - Cannot Save Relational Value
body: <p>I'm getting an error when I simply try to save data. Here is what I'm doing...</p>
  
  <p>1) First I Fetch using a Category object:</p>
  
  <pre><code>let categories: NSFetchRequest&lt;Categories&gt; = Categories.fetchRequest()
  categories.predicate = NSPredicate(format: "id==%@", '25')
  var category = try managedObjectContext.fetch(categories)[0]
  </code></pre>
  
  <p>2) Then I set the values on a new Subcategories object:</p>
  
  <pre><code>let subcategory = NSEntityDescription.insertNewObject(forEntityName: "Subcategories", into: managedObjectContext) as! Subcategories
  subcategory.text = "Some text..."
  subcategory.categories = category
  </code></pre>
  
  <p>3) Lastly I save:</p>
  
  <pre><code>managedObjectContext.save()
  </code></pre>
  
  <p>***** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '<strong>* -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[0]'</strong></p>
  
  <p>Category is not nil though because I can print it immediately before saving. I think there is a problem with the managedObjectContext.</p>