I am using NSArrayController Binding to populate NSTableView from core data. NSArrayController is connected to mainQueueConcurrencyType managed object context(main managed object).
parent of main managed object context is privateQueueConcurrencyType (background managed object context). Save call on main managed object context will push changes to background managed object context and save on background managed object context will save to persistent store.
Prepares contents and Editable are enabled in xib for NSArrayController
Core data table :
Path
Date
Status
I have unique constraints added to path.
Sometimes NSArrayController is not removing deleted object from arranged object after core data save.
[context performBlock:^{
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"entity" inManagedObjectContext:context];
[fetchRequest setEntity:entity];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"path ==%@", path];
[fetchRequest setPredicate:predicate];
NSError *error = nil;
NSArray *fetchedObjects = [context executeFetchRequest:fetchRequest error:&error];
SyncStatusEntry *syncStatus = [fetchedObjects firstObject];
NSInteger status = syncStatus.status.integerValue;
context deleteObject:syncStatus];
[context save:nil];
// Sometimes NSArrayController still have this object
}];
Can anyone please help me out?
Apparently
NSArrayControlleris notified when something changes in the context. This notification is sent inmergeChangesFromContextDidSaveNotification:which is automatically called ifautomaticallyMergesChangesFromParentisYES.