3

I recently upgraded a project to SDWebImage 4.0, which I'm only using to cache images and later retrieve them. Had this working flawlessly on the 3.x version. I'm now getting the following error after migrating...

-[SDImageCache storeImage:forKey:toDisk:completion:]: unrecognized selector sent to instance 0x174097cf0

This seems like it should be a simple error to resolve, but after multiple attempts, I'm unable to fix it.

Here is my previous code from the 3.x API...

@property (strong, nonatomic) SDImageCache *imageCache;
- (SDImageCache *)imageCache {

    if (!_imageCache) {
        _imageCache = [[SDImageCache alloc] initWithNamespace:NAME_SPACE_IMAGE_CACHE];

    }

    return _imageCache;
}


    [self.imageCache storeImage:[UIImage imageWithContentsOfFile:imageData.imageURL.path] forKey:imageData.imageURL.absoluteString toDisk:YES];

Here is my updated code for the 4.0 API, which is the line of code throwing the error...

[self.imageCache storeImage:[UIImage imageWithContentsOfFile:imageData.imageURL.path] forKey:imageData.imageURL.absoluteString toDisk:YES completion:^{
                                    NSLog(@"INFO: Image cached successfully!");
                                }];

Could someone please help clarify what the issue is?

Thanks in advance!

SonnyB
  • 269
  • 3
  • 12

2 Answers2

0

I try like this and it works, you must shift + cmd + k and build again, must solve the problem as is pointed out here https://github.com/rs/SDWebImage/issues/1602

#import "ViewController.h"

@interface ViewController ()
@property SDImageCache * imageCache;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.imageCache = [SDWebImageManager sharedManager].imageCache;
    // Do any additional setup after loading the view, typically from a nib.
    [_imageCache storeImage:[UIImage imageNamed:@"test"] forKey:@"testKey" toDisk:YES completion:^{
        NSLog(@"INFO: Image cached successfully!");
    }];
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end

CONSOLE OUTPUT

2017-07-11 00:55:12.146 SDWebImageSOQuestion[17275:339149] INFO: Image cached successfully!

Hope this helps

Community
  • 1
  • 1
Reinier Melian
  • 20,519
  • 3
  • 38
  • 55
  • Really appreciate your help...unfortunately, tried you code and got the same issue. But the issue seems to be with the way I'm passing the image. This has grown from very irritating to complete and total frustration! My working project is now totally broken as a result of the developers changing the API. Are there any working examples of just caching images with the 4.0 SDWebImage? I googled it and have not found any! – SonnyB Jul 11 '17 at 11:20
  • @SonnyB can you post your crash log?, to see if I can se something? – Reinier Melian Jul 11 '17 at 12:24
  • Hi Reiner. Sure, I'll be glad to post that once I get home. How do I get that so it's postable, i. e. copy and paste? You're talking about what I see in the debugger view in Xcode, correct? Thank you again for the assistance! – SonnyB Jul 11 '17 at 14:21
  • @SonnyB yes when you app crash copy what console logs prints and post it here – Reinier Melian Jul 11 '17 at 15:24
  • Oh, I had already provided that above for the most part... 2017-07-11 07:29:36.546566-0400 CollectionView-POC[7032:1431524] -[SDImageCache queryCacheOperationForKey:done:]: unrecognized selector sent to instance 0x170090130 – SonnyB Jul 11 '17 at 21:22
  • I did update my original post as well to show how I'm instantiating the SDImageCache object. – SonnyB Jul 11 '17 at 21:40
  • I found this thread on the SDWebImage github page which is the exact same issue. The only problem is the guy does not elaborate on how I fixed it. I don't understand his solution... https://github.com/rs/SDWebImage/issues/1602 – SonnyB Jul 11 '17 at 23:01
  • @SonnyB you must clean and rebuild to solve the issue!, my answer was updated to help to any other with the same issue – Reinier Melian Jul 11 '17 at 23:08
  • @SonnyB let know if this clean and rebuild solves your issue – Reinier Melian Jul 11 '17 at 23:21
  • Nope. Same exact damn issue! I don't understand what's causing this. I know it's not the code. I'm using code completion so I'm calling a legit method on this object. And I had actually done the clean and build previously, but for other reasons....had no idea it was required for this. At any rate, I still get the same error on that method call. Is it possible to just revert back to 3.8.2? I don't need 4.0 at all and a working app is now COMPLETELY broken as a result. – SonnyB Jul 12 '17 at 01:36
  • @SonnyB you can always go back to your previous version just change the version in your pod file and run pod install --verbose, any further assistance needed? let me know – Reinier Melian Jul 12 '17 at 01:46
  • Thank you!!!! I was able to go back to 8.3 and now it's working again after reverting my code! Can't thank you enough! – SonnyB Jul 12 '17 at 10:45
0

I had the same issue when my pod updated to 5.0. To fix it I needed to...

Change

[imageCache clearDisk];

To

[imageCache clearDiskOnCompletion:^{

}];
Tim
  • 1,428
  • 19
  • 26