Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Image Manager
final fileprivate class Weak<A: AnyObject> {
weak var value: A?
init(_ value: A) {
self.value = value
final class ImageManager {
fileprivate var values: [URL:Weak<Resource<UIImage>>] = [:]
func load(url: URL) -> Resource<UIImage> {
if let v = values[url]?.value { return v }
let loader = Resource(Endpoint(imageURL: url))
values[url] = Weak(loader)
return loader
static let shared = ImageManager()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.