Hi Readers,
This blog includes the concept of how to store image data in a cache memory with the help of SDWebImageManager. First of all, we need to install pods in the application to use SDWebImageManager, after creation of pod file you need to include two lines in the pod file which are given below:-
platform :ios, 9.0
pod 'SDWebImage', '~>3.8'
After pod file installation process you also need to import file which is given below:-
#import <SDWebImage/UIImageView+WebCache.h>
Now given below is the code to store image information in cache memory:-
NSString *imageString=@"http://www.istonsoft.com/blog/wp-content/uploads/2015/03/ios.png";
NSURL *imageURL=[[NSURL alloc]initWithString: imageString];
SDWebImageManager *imageManager = [SDWebImageManager sharedManager];
[imageManager downloadImageWithURL:imageURL
options:0
progress:^(NSInteger receivedSize, NSInteger expectedSize) {
// progression tracking code
}
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
if (image) {
// you can also view image in UIImageView according to your need
NSLog(@"%@",image);
}
}];
Use of storing an image in a cache is that next time when you will execute the application you will get an array of a downloaded image so from a cache that image will be fetched and take less time for execution.
Hope this code will help you to store image information in cache memory.
2 Comment(s)