Skip to content

Instantly share code, notes, and snippets.

@sergii-frost
Last active August 29, 2015 14:07
Show Gist options
  • Save sergii-frost/f1206eaa0bf1e740375a to your computer and use it in GitHub Desktop.
Save sergii-frost/f1206eaa0bf1e740375a to your computer and use it in GitHub Desktop.
Example of using SDWebImage
- (UIImage *)userImage
{
UIImage *cachedImage = nil;
NSString *imagePath = self.imageFilename;
if (imagePath)
{
SDWebImageManager *manager = [SDWebImageManager sharedManager];
NSURL *imageURL = [NSURL URLWithString:imagePath];
if ([manager diskImageExistsForURL: imageURL])
{
cachedImage = [[manager imageCache] imageFromDiskCacheForKey:imagePath];
}
else
{
[self cacheUserImageForFilename:imagePath];
}
}
return cachedImage;
}
- (void) cacheUserImageForFilename:(NSString *)filePath
{
SDWebImageManager *manager = [SDWebImageManager sharedManager];
NSURL *imageURL = [NSURL URLWithString:filePath];
if (![manager diskImageExistsForURL:imageURL])
{
[manager downloadImageWithURL:imageURL
options:0
progress:nil
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL)
{
NBULogDebug(@"Image loaded %@", error ? error.debugDescription : @"SUCCESS");
}];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment