Created
February 4, 2019 22:49
-
-
Save sisoje/5b015f34c5270fe8ecf26c53ad5d1175 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
class GenericCache<H: Hashable, V: AnyObject> { | |
let nsCache = NSCache<AnyObject, V>() | |
subscript(_ h: H) -> V? { | |
get { | |
return nsCache.object(forKey: h as AnyObject) | |
} | |
set { | |
if let v = newValue { | |
nsCache.setObject(v, forKey: h as AnyObject) | |
} else { | |
nsCache.removeObject(forKey: h as AnyObject) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment