Bordertown Labs Blog

Notes from Bordertown Labs with posts regarding software development for the iPhone, Ruby on Rails, tips and code.

» Contact with inquiries.


Visualize your geodata in augmented reality with 3DAR by Spot Metrix.


Posts tagged "blocks"

Sep 20th, 2011 @ 5:38 pm

Using GCD and Blocks Effectively


dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
    NSURL *url = [NSURL URLWithString:@"http://bit.ly/nUX01h"];
    NSURLRequest *req = [NSURLRequest requestWithURL:url];
    [NSURLConnection sendAsynchronousRequest:req
                                       queue:[NSOperationQueue currentQueue]
                           completionHandler:
     ^(NSURLResponse *res, NSData *data, NSError *err) {
         // Convert the data to a UIImage
         UIImage *image = [UIImage imageWithData:data];
           
         // Scale the image
         UIImage *thumbImage = nil;
         CGSize newSize = CGSizeMake(90, (90 / image.size.width) * image.size.height);
         UIGraphicsBeginImageContext(newSize);
         [image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
         thumbImage = UIGraphicsGetImageFromCurrentImageContext();
         UIGraphicsEndImageContext();
           
         dispatch_async(dispatch_get_main_queue(), ^{
             self.imageView.image = thumbImage;
         });
     }];
});




Comments (View)

 


 

Archive · RSS · Theme by Autumn