我对dispatch_async有疑问。我想确保队列完成执行,因为我需要返回一个仅在块完成时获得的值。
dispatch_queue_t downloadQueue = dispatch_queue_create("flickr downloader", NO);
dispatch_async(downloadQueue, ^{
NSArray *photos = [[FlickrFetcher photosInPlace:self.listOfPlacesChosenPlaceDictionary maxResults:50] mutableCopy];
dispatch_async(dispatch_get_main_queue(), ^{
self.photoAtThePlace = photos;
});
});
dispatch_release(downloadQueue);
return [self.photoAtThePlace mutableCopy];
目前返回值为nil,因为调用return函数时dispatch_async(dispatch_get_main_queue(),^ {..}尚未执行。如何在调用return之前确保完成此操作?谢谢!