Skip to content

Instantly share code, notes, and snippets.

@gungorbasa
Created September 26, 2017 20:44
Show Gist options
  • Save gungorbasa/088dca7492617e54be2caeff8515bcdf to your computer and use it in GitHub Desktop.
Save gungorbasa/088dca7492617e54be2caeff8515bcdf to your computer and use it in GitHub Desktop.
import UIKit
class ImageCache {
static let shared = ImageCache()
fileprivate let cache = NSCache<NSString, UIImage>()
func set(key: String, image: UIImage) {
DispatchQueue.main.sync {
cache.setObject(image, forKey: key as NSString)
}
}
func get(key: String) -> UIImage? {
return cache.object(forKey: key as NSString)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment