Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Foundation
- class Cache<T: AnyObject>: NSCache {
- subscript(key: AnyObject) -> T? {
- get {
- return objectForKey(key)
- }
- set {
- if let value = newValue {
- setObject(value, forKey: key)
- } else {
- removeObjectForKey(key)
- }
- }
- }
- func objectForKey(key: AnyObject) -> T? {
- return super.objectForKey(key) as? T
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement