Reputation: 997
I am using AfNetworking version ~> 1.3.4, which is added by cocoaPods. And I can't upgrade to 2.0 because most of the methods are used in my Application.
AFImageCache (in UIImageView+AFNetworking) cannot be cleared when a new image with the same URL is used
I supposed to add the following method in "UIImageView+AFNetworking" Class for this .
+ (void)clearCachedImages {
[[[self class] af_sharedImageCache] removeAllObjects];
}
As because AFNetworking is in my cocoaPods. I am unable to add. Please help me how to add this method by category / Subclass?
EDIT:
I have tried the following
@class AFImageCache;
@interface SPUtility : NSObject
{
}
@end
@implementation SPUtility
+ (void)clearCachedImages {
[[AFImageCache af_sharedImageCache] removeAllObjects]; //shows following error
}
@end
Error: No Known class method for selector 'af_sharedImageCache' 2. Receiver 'AFImageCache' for class message is a forward Declaration
Upvotes: 1
Views: 259
Reputation: 39978
Make a category for UIImageView
as your af_sharedImageCache
is in UIImageView (AFNetworking)
SPUtility.m
@interface UIImageView (MyMethods)
+ (NSCache *)af_sharedImageCache;
@end
//you don't have to implement method since it's already defined in UIImageView (AFNetworking)
//It's just for the happiness of the compiler
@implementation SPUtility
+ (void)clearCachedImages {
[[UIImageView af_sharedImageCache] removeAllObjects];
}
@end
Upvotes: 3