Skip to content

Commit 7458f13

Browse files
authored
Merge pull request #93 from SDWebImage/upgrade_sdwebimage_5_7
Upgrade the dependency of SDWebImage 5.7.0
2 parents 43c418d + 4613ebf commit 7458f13

File tree

5 files changed

+16
-42
lines changed

5 files changed

+16
-42
lines changed

Cartfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
github "SDWebImage/SDWebImage" ~> 5.3
1+
github "SDWebImage/SDWebImage" ~> 5.7

Package.resolved

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ let package = Package(
1717
dependencies: [
1818
// Dependencies declare other packages that this package depends on.
1919
// .package(url: /* package url */, from: "1.0.0"),
20-
.package(url: "https://github.com/SDWebImage/SDWebImage.git", from: "5.3.0")
20+
.package(url: "https://github.com/SDWebImage/SDWebImage.git", from: "5.7.0")
2121
],
2222
targets: [
2323
// Targets are the basic building blocks of a package. A target can define a module or a test suite.

SDWebImageSwiftUI.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ It brings all your favorite features from SDWebImage, like async image loading,
3434
}
3535

3636
s.weak_frameworks = 'SwiftUI', 'Combine'
37-
s.dependency 'SDWebImage', '~> 5.3'
37+
s.dependency 'SDWebImage', '~> 5.7'
3838
s.swift_version = '5.1'
3939
end

SDWebImageSwiftUI/Classes/ImageManager.swift

Lines changed: 11 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -110,45 +110,19 @@ public final class ImageManager : ObservableObject {
110110
/// Prefetch the initial state of image, currently query the memory cache only
111111
func prefetch() {
112112
isFirstPrefetch = false
113-
// Use the options processor if provided
114-
let options = self.options
115-
var context = self.context
116-
if let result = manager.optionsProcessor?.processedResult(for: url, options: options, context: context) {
117-
context = result.context
118-
}
119-
// TODO: Remove transformer for cache calculation before SDWebImage 5.7.0, this is bug. Remove later
120-
let transformer = (context?[.imageTransformer] as? SDImageTransformer) ?? manager.transformer
121-
context?[.imageTransformer] = nil
122-
// TODO: before SDWebImage 5.7.0, this is the SPI. Remove later
123-
var key: String?
124-
let selector = Selector(("cacheKeyForURL:context:"))
125-
if manager.responds(to: selector) {
126-
key = manager.perform(selector, with: url, with: context)?.takeUnretainedValue() as? String
127-
} else {
128-
key = manager.cacheKey(for: url)
129-
}
130-
if let transformer = transformer {
131-
key = SDTransformedKeyForKey(key, transformer.transformerKey)
113+
var options = self.options
114+
if options.contains(.fromLoaderOnly) {
115+
// If user indeed ignore cache, don't do prefetch
116+
return
132117
}
133-
// Shortcut for built-in cache
134-
if let imageCache = manager.imageCache as? SDImageCache {
135-
let image = imageCache.imageFromMemoryCache(forKey: key)
118+
// Use `.fromCacheOnly` to query cache only
119+
options.insert(.fromCacheOnly)
120+
var context = self.context ?? [:]
121+
context[.queryCacheType] = SDImageCacheType.memory.rawValue
122+
// Use `.queryCacheType` to query memory cache only
123+
manager.loadImage(with: url, options: options, context: context, progress: nil) { (image, data, error, cacheType, finished, imageUrl) in
124+
// This will callback immediately
136125
self.image = image
137-
if let image = image {
138-
self.successBlock?(image, .memory)
139-
}
140-
} else {
141-
// This callback is synchronzied
142-
manager.imageCache.containsImage(forKey: key, cacheType: .memory) { [unowned self] (cacheType) in
143-
if cacheType == .memory {
144-
self.manager.imageCache.queryImage(forKey: key, options: options, context: context) { [unowned self] (image, data, cacheType) in
145-
self.image = image
146-
if let image = image {
147-
self.successBlock?(image, cacheType)
148-
}
149-
}
150-
}
151-
}
152126
}
153127
}
154128

0 commit comments

Comments
 (0)