7

I'm trying to store an array of string in user defaults using the AppStorage property wrapper like this:

@AppStorage("History") var history: [String] = ["End of history"]

however I get the error No exact matches in call to initializer

Is this a limitation of AppStorage because UserDefaults can store arrays if I'm not wrong? What is a workaround I can use?

Arnav Motwani
  • 707
  • 7
  • 26
  • AppStorage does not have initializers for containers, only for simple concrete types supported by UserDefaults. So if you need to pack array then you need to encode/decode that manually (say to Data) or use custom property wrapper around UserDefaults as before. – Asperi May 03 '21 at 11:47
  • https://stackoverflow.com/questions/52273624/swift-user-defaults-array – lorem ipsum May 03 '21 at 19:22

0 Answers0