Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SDWebImage checking if image cached using Swift: Ambiguous Reference

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.

like image 825
onemillion Avatar asked Mar 08 '16 14:03

onemillion


2 Answers

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)
like image 146
JAL Avatar answered Oct 06 '22 02:10

JAL


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
}
like image 43
Ric Santos Avatar answered Oct 06 '22 02:10

Ric Santos