Attempt to set a non-property-list object as an NSUserDefaults

前端 未结 11 1715
闹比i
闹比i 2020-11-22 15:00

I thought I knew what was causing this error, but I can\'t seem to figure out what I did wrong.

Here is the full error message I am getting:

Attempt to se         


        
11条回答
  •  醉梦人生
    2020-11-22 15:46

    Swift- 4 Xcode 9.1

    try this code

    you can not store mapper in NSUserDefault, you can only store NSData, NSString, NSNumber, NSDate, NSArray, or NSDictionary.

    let myData = NSKeyedArchiver.archivedData(withRootObject: myJson)
    UserDefaults.standard.set(myData, forKey: "userJson")
    
    let recovedUserJsonData = UserDefaults.standard.object(forKey: "userJson")
    let recovedUserJson = NSKeyedUnarchiver.unarchiveObject(with: recovedUserJsonData)
    

提交回复
热议问题