I'm trying a multithreaded Core Data implementation on iPhone SDK 3.1.3. I have two different NSManagedObjectContext objects for each thread and I am registering for the change notifications on one thread like below:
- (void)setup {
DLog(@"Registering for NSManagedObjectContext notifications");
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self selector:@selector(test:) name:@"NSManagedObjectContextWillSaveNotification" object:nil];
[nc addObserver:self selector:@selector(test:) name:@"NSManagedObjectContextDidSaveNotification" object:nil];
[nc addObserver:self selector:@selector(test:) name:@"NSManagedObjectContextObjectsDidChangeNotification" object:nil];
}
- (void)test:(NSNotification *)notif {
DLog(@"Test callback");
}
In my other thread I am saving the second context like so:
NSError *error = nil;
[managedObjectContext save:&error];
if (error) {
ALog(@"Error occured while trying to save a NewsStory object");
}
else {
DLog(@"Saving context");
}
The notification callback method never gets executed though, which makes me believe these notifications are never posted?
My log shows the following:
Registering for NSManagedObjectContext notifications
Saving context
...
Saving context