Is there anyway that i can save an NSTimer to UserDefaults
and NSKeyedUnarchiver
and use it later ? Below is my example code
static var timerDictionary : [String:Timer]? {
get{
let outData = UserDefaults.standard.data(forKey: "timerDictionary") ?? Data()
if let dict = NSKeyedUnarchiver.unarchiveObject(with: outData) as? [String:Timer]?{
return dict
}else{
return [:]
}
}
set{
let data = NSKeyedArchiver.archivedData(withRootObject: newValue ?? [:])
UserDefaults.standard.set(data, forKey: "timerDictionary")
}
}
However my app crashes with 'NSInvalidArgumentException', reason: '-[__NSCFTimer encodeWithCoder:]
.