How to use cache my Class?
conloyal opened this issue · 1 comments
Hi,
How to use cache with my class?
I saved "my name" cache then get name from cache. It is incorrect.
Please help me.
Thanks, Huy.
EX:
class myclass : NSObject, NSCoding {
private var _name:String = ""
func setName(name:String) { self._name = name }
func getName() -> String { return self._name }
override init() {}
required init(coder aDecoder: NSCoder) { }
func encodeWithCoder(_aCoder: NSCoder) { }
}
MyViewController
let KEY_CACHE = "myapp"
do {
let cache = try Cache(name: KEY_CACHE)
if let rs = cache.objectForKey("test") {
log( " --------- Loaded ------------- ")
let name = rs.getName() //Incorrect: Name is empty.
} else {
log( " --------- Nil ------------- ")
let x:myclass = myclass()
x.setName("my name")
cache.setObject(x, forKey: "test")
}
} catch {
}