0
votes

I am not able to remove image cache which are cached by SDWebImage. I am using "UIImageView+UIActivityIndicatorForSDWebImage.h" I am caching image with this code.

[cell.imageView setImageWithURL:url placeholderImage:[UIImage imageNamed:@"image_icon.png"] usingActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];

Now sometime i want to remove cache of image because sometime same url will give me another image by server.

I am removing image cache using this code.

[[SDImageCache sharedImageCache] removeImageForKey:[self.imgArray objectAtIndex:indexForDelete] fromDisk:YES];

But is give's me error like:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSDictionaryM UTF8String]: unrecognized selector sent to instance 0x7fcb01f9bf70'

How to remove cache ??

3
I think self.imgArray is an array of Dictionary and not array of strings. - Varun
yes i got now solved. - sohan vanani

3 Answers

2
votes

in swift

SDImageCache.shared.removeImage(forKey: _imageURL?.description, withCompletion: nil)
1
votes

The method - (void)removeImageForKey:(NSString *)key fromDisk:(BOOL)fromDisk in the SDWebImage takes NSString as an argument.

In your above code it looks like [self.imgArray objectAtIndex:indexForDelete] gives you an an NSDictionary object and hence the crash.

So you would need something like this;

NSDictionary *imageDictionary = [self.imgArray objectAtIndex:indexForDelete];
NSString *cacheKeyToDelete = [imageDictionary objectForKey:@"YourKeyForImageCacheKey"];

[[SDImageCache sharedImageCache] removeImageForKey:cacheKeyToDelete fromDisk:YES];
0
votes

Try this, updating single image url with SDWebImageRefreshCached options.

Objective-C:

[self.imageView sd_setImageWithURL:[NSURL URLWithString:urlStr] placeholderImage:[UIImage imageNamed:@"???"] options:SDWebImageRefreshCached];

Swift: u can translate it by method name