My app has a single MOC that is created on the main thread when app is launched. However, I get unexpected behavior (very rarely) where NSManagedObjectContextDidSaveNotification is posted on a background thread while I expect it on the main thread. Here is the code:
[[NSNotificationCenter defaultCenter] addObserverForName:NSManagedObjectContextDidSaveNotification
object:self.managedObjectContext
queue:nil
usingBlock:^(NSNotification *notification) {
if (![NSThread isMainThread]) {
// Rarely getting here, not sure why?
}
}];
The self.managedObjectContext
refers to the MOC instance I create on the main thread when app is loaded.
Any ideas what could be the reason?