I‘d like to store my user defaults in a class. With the old Swift data flow it was possible to use it in a class. Now, with the new system (Xcode 15, Beta 2), it doesn’t work anymore. Is there any way to use it? Maybe a workaround?
This is how it worked before:
import SwiftUI
class UserInfo: ObservableObject {
@AppStorage("username") var username: String = ""
}
And now I want to use the new system:
import SwiftUI
@Observable class UserInfo {
@AppStorage("username") var username: String = ""
}
Unfortunately, it doesn’t work.
@AppStorage
inside a class is a bad idea since there is nobody
to be called when it changes and you aren't supposed to store models in user defaults. – Albers