Using @AppStorage

150 Views Asked by At

is it possible to store a set of boolean variables by using @AppStorage.

Currently I use e.g. this situation:

class UserSettings: ObservableObject {

 @Published var localTime : Bool {
        didSet {
             UserDefaults.standard.set(localTime, forKey:"local")
         }
     }
      ...   
     
     init() {
      self.localTime = UserDefaults.standard.object(forKey: "local") as? Bool ?? false
      
      ...
     }
}

Thanks for your support.

Peter

1

There are 1 best solutions below

0
On

Try this:

class UserSettings: ObservableObject {
    @AppStorage("local") var localTime = false
}