consider following piece of code simple request user data particular username.
- (void)updateinformation { afhttprequestoperationmanager *httpmanager = [afhttprequestoperationmanager sharedmanager]; nsdictionary *params = @{@"username": self.username}; afhttprequestoperation *operation = <create_op> [operation setcompletionblockwithsuccess:^(afhttprequestoperation *operation, id response){ // use response populate user // self.fullname = response[@"fullname"]; }failure:nil]; [httpmanager.operationqueue addoperation:operation]; } this code part of category particular entity e.g. user.
now method called in scheduleblock. scheduleblock (http://cocoadocs.org/docsets/xmppframework/3.6.1/classes/xmppcoredatastorage.html#//api/name/scheduleblock:):
this method asynchronously invokes given block (dispatch_async) on storagequeue.
now question simple — request response received in different thread compared storagequeue on updateinformation method called => there needs different managed object context needs created store object , sync changes context storage queue. is right?
another question — there better way of handling this, i.e. not creating new context , trying sync storage queue context?
you can use same context since coming in thread/queue need wrap core data processing code in performblock: or performblockandwait: processing done on correct thread associated context.
Comments
Post a Comment