iOS - Grand Central Dispatch getting value from block in dispatch_async -
iOS - Grand Central Dispatch getting value from block in dispatch_async -
i'm using below code download info web. right need retain info have done? nslog statement within block shows array has been populated, when run nslog outside block arrays show (null). how save info outside dispatch_async method?
__block nsarray *downloadedcareerids; __block nsarray *diskcareerids; dispatch_async(dispatch_get_global_queue(dispatch_queue_priority_default, 0), ^{ /* download stuff */ downloadedcareerids = [[careersparser idsfrom:@"web"] retain]; diskcareerids = [[careersparser idsfrom:@"disk"] retain]; dlog(@"downloadedcareerids: %@", downloadedcareerids); dlog(@"diskcareerids: %@", diskcareerids); }); dlog(@"downloadedcareerids: %@", downloadedcareerids); dlog(@"diskcareerids: %@", diskcareerids);
dispatch_async non blocking method homecoming immediately. when dlog statements outside block called, not have been set. hence don't see values internal log statements.
if want deed on info within same method, have either send blocking dispatch_sync pointless or can phone call methods within block.
dispatch_async(dispatch_get_global_queue(dispatch_queue_priority_default, 0), ^{ .... [self dostuffwiththearrays]; }); once block executed objects available provided instance variables or lose references.
ios return-value grand-central-dispatch
Comments
Post a Comment