Protect the runtime hack for user who use before SDWebImage 5.6.0

This commit is contained in:
DreamPiggy 2020-04-01 17:50:46 +08:00
parent 96a2832442
commit 9b8c19df1d
1 changed files with 7 additions and 1 deletions

View File

@ -120,7 +120,13 @@ public final class ImageManager : ObservableObject {
let transformer = (context?[.imageTransformer] as? SDImageTransformer) ?? manager.transformer
context?[.imageTransformer] = nil
// TODO: before SDWebImage 5.7.0, this is the SPI. Remove later
var key = manager.perform(Selector(("cacheKeyForURL:context:")), with: url, with: context)?.takeUnretainedValue() as? String
var key: String?
let selector = Selector(("cacheKeyForURL:context:"))
if manager.responds(to: selector) {
key = manager.perform(selector, with: url, with: context)?.takeUnretainedValue() as? String
} else {
key = manager.cacheKey(for: url)
}
if let transformer = transformer {
key = SDTransformedKeyForKey(key, transformer.transformerKey)
}