6

I am trying to find out if an image has already been cached using SDWebImage but when I try to use this method I get the error "Ambiguous reference to member 'cachedIageExistsForURL".

let bool = SDWebImageManager.cachedImageExistsForURL(imgURL)

I am using Swift and I have a bridging header to use the library.

JAL
  • 41,701
  • 23
  • 172
  • 300
onemillion
  • 682
  • 5
  • 19

2 Answers2

7

cachedImageExistsForURL is not a class method on SDWebImageManager, it's an instance method which you need to use on the sharedInstance:

SDWebImageManager.sharedManager().cachedImageExistsForURL(imgURL)
JAL
  • 41,701
  • 23
  • 172
  • 300
  • As of v5.x I don't believe this will work any longer. They have shifted to these methods being asynchronous, with the result being returned in a completion block. **EDIT:** My mistake, it looks like they may have been removed even before 5.x. https://sdwebimage.github.io/sdwebimage-40-migration-guide.html – Stoph Oct 01 '19 at 14:04
7

As of SDWebImage 5 there is a new class, SDImageCache, which provides a synchronous method to use:

SDImageCache.shared.diskImageDataExists(withKey: urlString)

There is also an asynchronous method with a completion handler:

SDImageCache.shared.diskImageExists(withKey: urlString) { exists in
    // your code here
}
Ric Santos
  • 15,419
  • 6
  • 50
  • 75