I have a DataManager class which returns a shared instance:
+ (DataManager *)sharedInstance;
{
static DataManager *sharedInstance = nil;
static dispatch_once_t pred;
dispatch_once(&pred, ^{
sharedInstance = [[DataManager alloc] init];
});
return sharedInstance;
}
In here I keep track of my managedObjectContext, managedObjectModel, persistentStoreCoordinator.
I also have a method where I pull out items for displaying:
- (NSArray *)getItems
{
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] initWithEntityName:@"Item"];
return [[self managedObjectContext] executeFetchRequest:fetchRequest error:nil];
}
Now in my main app I have a view controller when I call this getItems and then modify items individually. So for example set item.itemName = @"testName"; and then call my save method.
I also have an iOS 8 where in my TodayViewController I also call the getItems method. I have an NSNotification which detects for managedObjectContext saves.
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refetchItems) name:NSManagedObjectContextDidSaveNotification object:[[DataManager sharedInstance] managedObjectContext]];
These refetched items does get called but returns the outdated NSManagedObjects. So for example the itemName has not changed to @"testName".
Where am I going wrong? Let me know if you need to see any other code.
Thanks!