I have an NSDictionary
which I cached. I need to implement a time-based setObject with timestamp. NSCache Class
doesn't have a setExpiry. Any help would be appreciated.
This is the extension I have so far:
import Foundation
extension NSCache {
class var sharedInstance : NSCache {
struct Static {
static let instance : NSCache = NSCache()
}
return Static.instance
}
}
I found NSCache Extension
at http://nshipster.com/nscache/ . Any easy way to implement with an expiry timestamp?
extension NSCache {
subscript(key: AnyObject) -> AnyObject? {
get {
return objectForKey(key)
}
set {
if let value: AnyObject = newValue {
setObject(value, forKey: key)
} else {
removeObjectForKey(key)
}
}
}
}