I faced with a problem that the core data don't see any changes in my predicate when I'm tryin to modify it. I spent alot of time trying to find why doesn't my fetched property show me the correct results (see code below) and finally after another coffee break I've seen that (SUDDENLY!) my fetched property starts to work fine. Is there some delay with updating datamodel? Or should I go on breaks more often?
-(void)printData{
NSFetchRequest *request = [[NSFetchRequest alloc] initWithEntityName:@"Empl"];
NSError *error;
NSArray *empls = [[self managedObjectContext] executeFetchRequest:request error:&error];
for (NSManagedObject *emplMO in empls){
NSString *output = [NSString stringWithFormat:@"%@ \n", [emplMO valueForKey:@"emplName"]];
[self.managedObjectContext refreshObject:emplMO mergeChanges:YES];
NSArray *allChairs = [emplMO valueForKey:@"allChairs"];
output = [output stringByAppendingFormat:@" has %d chairs \n", allChairs.count];
NSLog(@"%@", output);
}
}
Are you using single NSManagedObjectContext across your whole app?
from Apple Developer Reference:
Sounds like if you have two contexts, the objects changed in contextA will need to be persisted out to store and back out again for the contextB to see them... UIManagedDocument does autosaving. You may see slight delay/gap in core data update/fetch if you are using 2 or more contexts.