Created
January 20, 2019 21:25
-
-
Save thexande/ccd4e1fe00a355647b70c8067d82f35b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Foundation | |
| import CoreGraphics | |
| import SDWebImage | |
| final class ImageAspectRatioCache { | |
| var aspectLookup: [URL:CGFloat] = [:] | |
| func produceAspectRatios(for images: [URL], completion: (() -> Void)?) { | |
| let group = DispatchGroup() | |
| for url in images { | |
| group.enter() | |
| SDWebImageDownloader.shared().downloadImage(with: url, | |
| options: [], | |
| progress: nil) { [weak self] (image, _, _, _) in | |
| if let size = image?.size { | |
| self?.aspectLookup[url] = (size.width / size.height) | |
| } | |
| group.leave() | |
| } | |
| } | |
| group.notify(queue: DispatchQueue.global()) { | |
| completion?() | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment