davidsteppenbeck / ObservableUserDefault

A Swift macro that adds accessor blocks to properties in `Observable` classes that read and write values in `UserDefaults`.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to work with [String] and [String]?

davidarice opened this issue · comments

Is there a trick to getting this to work with an array? At the moment I simply using the following method:

var favorites: [String] { get { access(keyPath: \.favorites) return UserDefaults.standard.value(forKey: "favorites") as? [String] ?? [] } set { withMutation(keyPath: \.favorites) { UserDefaults.standard.set(newValue, forKey: "favorites") } } }

Thanks for pointing that out. Fixed it, should now work with arrays and dictionaries.