I get this error every time I try to save my Core Data viewContext (managedObjectContext). What does it mean? Is this a Swift 3 bug?
Actual SIGARBT Error:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[0]I've narrowed it down to a relationship object. I am doing a Fetch to obtain the object, which looks good, but when I save it the error indicates it is nil. Interestingly, the exact code works perfectly on one entity, but for the life of me I cannot see why it won't work for the other.
Sample Code - Fetch Object from Entity1:
let fetchRequest: NSFetchRequest<Entity1> = Entity1.fetchRequest()
fetchRequest.predicate = NSPredicate(format: "myRowNumber==%@", "101") //Find a specific row
let fetchResult: Entity1 = try self.viewContext.fetch(fetchRequest)[0] //Grab result and cast it as Entity1
print("THE FETCH RESULT LOOKS GOOD: \(fetchResult.value(forKey: "myRowNumber")!)")Sample Code - Save to Entity2:
let entity2 = NSEntityDescription.insertNewObject(forEntityName: "Entity2", into: self.viewContext) as! Entity2
entity2.entity1 = fetchResult //Set the relationship object from Fetch above
entity2.text = "Some test text..."
viewContext.save() //Save the changes (try/catch removed) and that's when it crashes every time...