Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- dispatch_queue_t concurrentQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
- dispatch_async(concurrentQueue, ^{
- __block NSMutableArray *newImages;
- dispatch_sync(concurrentQueue, ^{
- newImages = [NSMutableArray array];
- // images retrieved using `NSURLConnection sendSynchronousRequest`
- });
- dispatch_sync(dispatch_get_main_queue(), ^{
- // display images to the user
- });
- });
- q = /* custom serial queue */
- urls = /* urls array */;
- NSMutableArray *images = [NSMutableArray new];
- for (NSURL *url in URLs) {
- NSURLRequest *req = [self imageRequestForURL:url];
- dispatch_async(q, ^{
- UIImage *image = [self imageFromRequest:req];
- [images addObject:newImage];
- }
- }
- dispatch_async(q, ^{
- dispatch_async(dispatch_get_main_queue(), ^{
- [self applyUpdatesForURLs:urls withImages:images];
- });
- }
- NSURL *url = [NSURL URLWithString:@"your server address"];
- NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:5];
- [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *theData, NSError *error){
- if (error == nil) {
- //do what you want with theData and update the UI
- }
- }];
Add Comment
Please, Sign In to add comment