Search code examples
cocoacore-datacocoa-bindings

New Core Data object doesn't show up in NSArrayController arrangedObjects


When I insert a new object in a Core Data managed object context and shortly after that try to find this new object in the NSArrayController (which is connect with the managedObjectContext through binding), I can't find it. I do the creation and search in one method.

My question now. How long does it take for a new inserted object to show up in the NSArrayControllers arrangedObject array?

Update: Here is the code for inserting and fetching the new objects

NSEntityDescription *entity = [[[self managedObjectModel] entitiesByName] objectForKey:@"EntityName"];
NSManagedObject *object = [[NSManagedObject alloc] initWithEntity:entity insertIntoManagedObjectContext:[self managedObjectContext]];
...
[[self managedObjectContext] processPendingChanges];

[arrayController fetch:nil];
NSArray* objects = [arrayController arrangedObjects]; //the new object is not present in the array

Solution

  • Just found a fix for this. I use the setSelectedObjects: method of the NSArrayController to select the object. Don't know why I didn't used this method anyway!