cocoa touch - NSManagedObjectContextDidSaveNotification not triggered in iOS 7 -
i have situation make changes properties of nsmanagedobject in main thread. belongs main managedobjectcontext of app.
my app has threading enabled downloads data, each thread has it's own managedobjectcontext created recent state of single persistentstore throughout application.
i implementing nsmanagedobjectcontextdidsavenotification
changes in moc merged main thread's moc too. below code it:
- (void)backgroundmocdidsave:(nsnotification*)notification { // probable fix for: http://stackoverflow.com/questions/3446983/collection-was-mutated-while-being-enumerated-on-executefetchrequest if (![nsthread ismainthread]) { [self performselectoronmainthread:@selector(backgroundmocdidsave:) withobject:notification waituntildone:yes]; return; } // merge background moc changes in main moc [self.managedobjectcontext mergechangesfromcontextdidsavenotification:notification]; }
registering notification:
[[nsnotificationcenter defaultcenter] addobserver:self selector:@selector(backgroundmocdidsave:) name:nsmanagedobjectcontextdidsavenotification object:nil];
strange things happen in ios 7 though. accessing nsmanagedobject created main moc:
- when modify property of managedobject belongs main moc (main thread) , perform
-save
-backgroundmocdidsave:
call not triggered - when not modify property of managedobject , perform
-save
operation on moc notification triggered
the same code working in ios 6. irrespective of whether changes done on managedobject or not, when -save
call triggered on it's moc notification nsmanagedobjectcontextdidsavenotification
gets triggered.
anyone faced problem before?
for i've noticed 1 thing that's wrong, i'm not sure it's causing error. nsmanagedobjectcontextdidsavenotification
sent on thread on moc calls save
running. merging should made on thread moc merging changes running on. in case works fine if changes merged background main moc, not other way around.
Comments
Post a Comment