Using @AppStorage on a class

138 views Asked by At

I have a class like this:

final class BiometricsAuthenticator {
  @AppStorage("appBlocked") var appBlocked = true
  ...
  context.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: reason) { success, authenticationError in
        if success {
          self.appBlocked = false
        } else {
          return
        }
      }

As you see, I use an @AppStorage to keep track of "appBlocked" property, as it's used on another views. It works perfectly, but I'm not sure it's the correct way of using it, outside a View. In fact, I've tried to use UserDefaults instead, but this way I can read the value, but not "toggle" it to be used for the rest of the views.

Could there be any problem using this way, or maybe in the future? What could be the correct way to make it work with UserDefaults?

0

There are 0 answers