Not sure how to use unarchivedDictionary to resolve a NSInvalidArgumentException crash using userDefaults within Swift

320 views Asked by At

I'm hitting the issue documented here and I'm trying to utilize NSKeyedUnarchiver.unarchivedDictionary, but I'm not sure what KeysofClasses or objectsOfClasses is wanting.

The structure of my dictionary is: [Int: [String: String]]

A bit of my code:

let encodedData = try NSKeyedArchiver.archivedData(withRootObject: widgetDictionary, requiringSecureCoding: false)

let outData = UserDefaults.standard.data(forKey: "flaggedWidgetDictKey")
let decodedData = NSKeyedUnarchiver.unarchivedDictionary(keysOfClasses:  [Int: [String: String]], objectsOfClasses: [Int: [String: String]], from: outData!))

The error:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Attempt to insert non-property list object for key jobCategory'

0

There are 0 answers