ios - setting property in dispatch_async but property is NULL after block finishes -


i using following code change property called topplaces inside view controller. line [flickrfetcher topplaces] returns nsarray , property topplaces is, of course, nsarray.

dispatch_queue_t downloadqueue = dispatch_queue_create("flickr topplace", null); dispatch_async(downloadqueue, ^{     nsarray *topplaces = [flickrfetcher topplaces];     dispatch_async(dispatch_get_main_queue(), ^{         self.topplaces = topplaces;     }); }); dispatch_release(downloadqueue); 

however, after block finishes executing, if log value of self.topplaces, still null reason. there missing?

your ivar not set until after current method has finished. call [flickrfetcher topplaces] running in parallel current method , takes random amount of time complete. when complete, makes call main thread, executed on next iteration of run loop

this means in second dispatch_async() block need call methods display data after setting ivar.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -