0

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'

Robert
  • 603
  • 3
  • 8
  • 17
  • Seeing the error, it seems that `archivedData` is creating the issue... What is `widgetDictionary`? – Larme Jun 02 '22 at 16:46
  • the `archivedData` is my attempt to resolve the crash. Before that I was doing `userDefaults?.set(widgetDictionary, forKey: "flaggedWidgetDictKey")` The `widgetDictionary` is `[0: ["Foo" : "Data"]]` – Robert Jun 02 '22 at 16:54
  • Concerning the previous error, I'm wondering if that's because the key of the diictionary can't be `Int` to be PropertyList Compliant, (as it's the same for JSON), to verify... – Larme Jun 02 '22 at 16:59
  • That would be interesting if `Int` could not be a key since Apple's documentation says it can https://developer.apple.com/documentation/swift/dictionary or maybe I'm reading it wrong. – Robert Jun 02 '22 at 17:02

0 Answers0