I wrote this code like this when I logged in, it is ok. but when I run again it is not working at all. in Xcode Version 11.2.1
this is my code:
You can do this in following way...
// Saving logged info here Userdefault
let result = jsonDict["result"] as? NSDictionary ?? [:]
let data = try! NSKeyedArchiver.archivedData(withRootObject: result, requiringSecureCoding: false)
UserDefaults.standard.set(data, forKey: "currentUser")
// Get data from Userdefault
let result = UserDefaults.standard.data(forKey: "currentUser")
if result != nil{
let dict = try! NSKeyedUnarchiver.unarchiveTopLevelObjectWithData(result!) as? NSDictionary ?? [:]
print("Current User Details : - \(dict)")
}