Skip to content

Commit

Permalink
Merge pull request alexiscreuzot#199 from ygag-minna/master
Browse files Browse the repository at this point in the history
caching image fix
  • Loading branch information
Alexis Creuzot authored Mar 21, 2024
2 parents fd07d8a + 5f55384 commit af3db61
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions SwiftyGif/UIImageView+SwiftyGif.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,16 @@ public extension UIImageView {

public extension UIImageView {

private static var fileURLKey: UInt8 = 0

var giffileURL: URL? {
get {
return objc_getAssociatedObject(self, &UIImageView.fileURLKey) as? URL
}
set {
objc_setAssociatedObject(self, &UIImageView.fileURLKey, newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
}
}
/// Download gif image and sets it.
///
/// - Parameters:
Expand Down Expand Up @@ -177,11 +187,13 @@ public extension UIImageView {
}

do {
let image = try UIImage(gifData: data, levelOfIntegrity: levelOfIntegrity)
manager.remoteCache[url] = data
setGifImage(image, manager: manager, loopCount: loopCount)
startAnimatingGif()
delegate?.gifURLDidFinish?(sender: self)
if self.giffileURL?.absoluteString == url.absoluteString {
let image = try UIImage(gifData: data, levelOfIntegrity: levelOfIntegrity)
manager.remoteCache[url] = data
setGifImage(image, manager: manager, loopCount: loopCount)
startAnimatingGif()
delegate?.gifURLDidFinish?(sender: self)
}
} catch {
report(url: url, error: error)
}
Expand Down

0 comments on commit af3db61

Please sign in to comment.