Saving Dictionary with Data into UserDefaults doesn't work

I'm trying to save a Dictionary to UserDefaults. My Dictionary is defined as [String:Data]. Since both String and Data are property objects, I expected this to work, but it doesn't: my app blows up with a "this class is not key-value coding compliant" error.

Is this a bug, or am I doing something wrong?

Replies

May have a look here:

  • https://www.hackingwithswift.com/books/ios-swiftui/saving-and-loading-data-with-userdefaults
  • https://www.hackingwithswift.com/read/12/2/reading-and-writing-basics-userdefaults

Thanks for the response. Actually, the problem was that my code was calling "setValue" instead of "set", which I guess happened because I chose the wrong autocomplete and didn't notice it right away. Once I fixed that it worked as expected.

@frankfrommadison Thanks for the feedback. That's the traps of autocompletion…

@flarosa Did you solve it ?