Skip to content

Instantly share code, notes, and snippets.

@chrismiles
Created March 6, 2012 02:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrismiles/1982953 to your computer and use it in GitHub Desktop.
Save chrismiles/1982953 to your computer and use it in GitHub Desktop.
UIImageView (CMAsyncExtension) - async load image from URL
@interface UIImageView (CMAsyncExtension)
- (void)asyncLoadImageFromURL:(NSURL *)imageURL;
@end
@implementation UIImageView (CMAsyncExtension)
- (void)asyncLoadImageFromURL:(NSURL *)imageURL
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:imageURL]];
if (image) {
dispatch_async(dispatch_get_main_queue(), ^{
self.image = image;
});
}
});
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment