I am trying to fetch a data from UserDefault
but when I am doing this I am getting error
var sharedPreference: UserDefaults = UserDefaults.init(suiteName: "user-key-value")!
func getLastLoginClientId() -> Int64? {
for (key, value) in sharedPreference.dictionaryRepresentation() {
if key == LAST_USER {
return value as! Int64
}
}
return nil
}
I am getting that my key is having some value but when returning it, it throws error.
This is how I save
func setLastLoginClientId(clientId: Int64) {
sharedPreference.set(clientId, forKey: LAST_USER)
sharedPreference.synchronize()
}