0

Here is the full error message I am getting:

as an NSUserDefaults/CFPreferences value for key Login_Data

2019-04-02 09:44:56.191207+0530 Level Up[238:4101] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Attempt to insert non-property list object

Here is my Code :

let data = response.result.value as! NSDictionary

print(data)

if data["error-code"] != nil {
    if data.object(forKey: "error-code")as! String == "\(200)"
    {

        let arrTimer = ((data.object(forKey: "data") as! NSDictionary).object(forKey: "timers") as! NSArray).mutableCopy() as! NSMutableArray

        UserDefaults.standard.set(arrTimer , forKey: "ArrayTimer")
        UserDefaults.standard.set((data.object(forKey: "data") as! NSDictionary), forKey: "Login_Data")

I am getting this when am changing user e-mail from backend. For the fresh user it works fine. I hope this is enough code to give you an idea o what I am trying to do.

vadian
  • 274,689
  • 30
  • 353
  • 361

1 Answers1

0

Looks like the issue is that the dictionary has NSNull or nil values and trying to store that in UserDefaults doesn't work. The library should probably use NSKeyedArchiver to get around that. Convert dictionary to data then save it in UserDefaults.