SDWebImage checking if image cached using Swift: Ambiguous Reference
Asked Answered
N

2

7

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.

Notions answered 8/3, 2016 at 14:41 Comment(0)
V
8

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)
Violoncellist answered 8/3, 2016 at 14:53 Comment(1)
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. sdwebimage.github.io/sdwebimage-40-migration-guide.htmlNoh
C
9

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
}
Curlew answered 18/12, 2019 at 23:47 Comment(0)
V
8

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)
Violoncellist answered 8/3, 2016 at 14:53 Comment(1)
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. sdwebimage.github.io/sdwebimage-40-migration-guide.htmlNoh

© 2022 - 2025 — McMap. All rights reserved.