TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

Using @AppStorage on a class

Forums > SwiftUI

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?

2      

Hacking with Swift is sponsored by RevenueCat.

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.