SWIFT 5.1 Mutablecopy

后端 未结 1 1823
天命终不由人
天命终不由人 2021-01-29 09:15

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:

1条回答
  •  时光取名叫无心
    2021-01-29 09:46

    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)")
    }
    

    0 讨论(0)
提交回复
热议问题