I have a mutable array of dictionary store image from url.So how to store image in application cache and i can view image when not have internet connection.
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
static NSString * CellIndentifier=@"CustomCell";
CustomCell *cell = (CustomCell*)[collectionView dequeueReusableCellWithReuseIdentifier:CellIndentifier forIndexPath:indexPath];
NSDictionary *dictVideo = [self.videoList objectAtIndex:indexPath.row];
[cell.indicator startAnimating];
//set title
NSString *titleVideo = [dictVideo objectForKey:@"Title"];
[cell.myLabel setText:titleVideo];
// set image url
NSString *urlVideo = [dictVideo objectForKey:@"Url"];
NSURL *url = [NSURL URLWithString:urlVideo];
cell.imageView.image = nil;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage * img = [[UIImage alloc]initWithData:data];
dispatch_sync(dispatch_get_main_queue(), ^{
NSLog(@"%ld %@ %@",(long)indexPath.row,titleVideo,url);
[cell.imageView setImage: img];
[cell.indicator stopAnimating];
});
});
return cell;
}