Last active
February 19, 2017 03:04
-
-
Save soffes/10d76eb09bc6387ab3ac30130ff80f81 to your computer and use it in GitHub Desktop.
Access NSCache with a subscript
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 | |
| extension NSCache { | |
| subscript(key: AnyObject) -> AnyObject? { | |
| get { | |
| return objectForKey(key) | |
| } | |
| set(object) { | |
| if let object = object { | |
| setObject(object, forKey: key) | |
| } else { | |
| removeObjectForKey(key) | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This doesn't work on swift 3 anymore