objective c - How do I track NSError objects across threads? -



objective c - How do I track NSError objects across threads? -

i have set of asynchronous calls beingness spawned using nsinvocationoperation:

- (void)listrequestqueue:(storedatalistrequest *)request { [openlistrequests addobject:request]; nsinvocationoperation *requestop = [[nsinvocationoperation alloc] initwithtarget:self selector:@selector(listrequeststart:) object:request]; [opqueue addoperation:requestop]; [requestop release]; } - (void)listrequeststart:(storedatalistrequest *)request { if(self.resourcedata == nil) { //todo fail appropriately... return; } storedatalistresponse *response = [self newlistresponseforproductid:request.productid]; [self performselectoronmainthread:@selector(listrequestfinish:) withobject:response waituntildone:no]; [response release]; [self performselectoronmainthread:@selector(cleanuplistrequest:) withobject:request waituntildone:no]; } - (void)listrequestfinish:(storedatalistresponse *)response { [self.delegate storedata:self didreceivelistresponse:response]; } - (storedatalistresponse *)newlistresponseforproductid:(nsstring *)productid { collectiondata *data = [self.resourcedata dataforproduct:productid]; if(data == nil) { //todo } storedatalistresponse *response = [[storedatalistresponse alloc] init]; response.productid = productid; if(productid != data.productid) { //todo fail; remove product list } response.name = nslocalizedstring(@"loading...", @"loading message"); response.blurb = nslocalizedstring(@"waiting response server", @"waiting website respond"); homecoming response; }

for each of todos in above code, should resolve issue , allow handlers know things have failed , why. looking @ nserror class , documentation, appears appropriate reply having problem figuring out how work nsinvocationoperation , performselectoronmainthread:withobject:waituntildone:. can nserrors out of newlistresponseforproductid: method changing this:

- (storedatalistresponse *)newlistresponseforproductid:(nsstring *)productid error:(nserror **)error;

how error generated main thread can deal failed request?

the easiest way run code on main thread utilize gcd , blocks on ios 4 , above. this:

dispatch_async(dispatch_get_main_queue(), ^(void) { // code run on main thread here, // variables in scope nserror captured. });

or utilize dispatch_sync() if know on background thread , want block finish on main thread before continue.

objective-c multithreading error-handling nserror

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -