Skip to content

Instantly share code, notes, and snippets.

@nloko
Last active January 18, 2016 19:55
Show Gist options
  • Save nloko/5a3bd6513fe20ed07ecd to your computer and use it in GitHub Desktop.
Save nloko/5a3bd6513fe20ed07ecd to your computer and use it in GitHub Desktop.
self.text = self.event.text;
__weak id wself = self;
NSString *imageUrl = self.event.imageUrl;
self.image = nil;
self.overlay.image = nil;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
UIImage *image = [ImageCache sharedCache] get:imageUrl];
if (!image) {
image = [[wself downloadImage:imageUrl] scaleWithWidth:cellWidth];
[ImageCache sharedCache] put:image withKey:imageUrl];
}
UIImage *blurredImage = [ImageCache blurredCache] get:imageUrl];
if (!blurredImage) {
blurredImage = [image blurRect:overlayRect];
[ImageCache blurredCache] put:blurredImage withKey:imageUrl];
}
dispatch_async(dispatch_get_main_queue(), ^{
// skip if the cell’s event has changed
if (![imageUrl isEqualToString:wself.event.imageUrl]) {
return;
}
wself.overlay.image = blurredImage;
wself.image = image;
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment