Reputation: 1574
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 ??
Upvotes: 0
Views: 3693
Reputation: 122
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
Upvotes: 0
Reputation: 134
in swift
SDImageCache.shared.removeImage(forKey: _imageURL?.description, withCompletion: nil)
Upvotes: 2
Reputation: 1807
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];
Upvotes: 1