Created
September 26, 2017 20:44
-
-
Save gungorbasa/088dca7492617e54be2caeff8515bcdf 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 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