iphone - mergeChangesFromContextDidSaveNotification deleting records -
i trying update records in coredata on background thread. creating nsmanagedobjectcontext's
each thread per documentation. registering notifications when data saved. however, mergechangesfromcontextdidsavenotification
deleting entries instead of updating them.
//notification callback - (void)_managedobjectcontextdidsave:(nsnotification *)notification { dispatch_async(dispatch_get_main_queue(), ^{ [self.managedobjectcontext mergechangesfromcontextdidsavenotification:notification]; }); } //per thread managed object context - (nsmanagedobjectcontext *)managedobjectcontext { if ([[[nsthread currentthread] threaddictionary] objectforkey:gvcontrollermanagedobjectcontextkey] == nil) { nspersistentstorecoordinator *coordinator = self._persistentstorecoordinator; if (coordinator != nil) { nsmanagedobjectcontext *managedobjectcontext = [[nsmanagedobjectcontext alloc] init]; [managedobjectcontext setpersistentstorecoordinator:coordinator]; if (![nsthread ismainthread]) { [[nsnotificationcenter defaultcenter] addobserver:self selector:@selector(_managedobjectcontextdidsave:) name:nsmanagedobjectcontextdidsavenotification object:managedobjectcontext]; } [[[nsthread currentthread] threaddictionary] setobject:managedobjectcontext forkey:gvcontrollermanagedobjectcontextkey]; [managedobjectcontext release]; } } return [[[nsthread currentthread] threaddictionary] objectforkey:gvcontrollermanagedobjectcontextkey]; }
looks using managed object thread (added property of objects updating).
Comments
Post a Comment