title: Biometric Authentication evaluation with swiftUI
body: <p>I've been able to get a rudimentary version of Face / Touch ID working inside my app. However, I want to add better fallbacks and error handling. </p>
  
  <p>So I've been researching how to do it. There are fantastic resources like this:</p>
  
  <p><a href="https://stackoverflow.com/questions/52092990/face-id-evaluation-process-not-working-properly/52093551#52093551">Face ID evaluation process not working properly</a></p>
  
  <p>However, I can't find anything that works inside a SwiftUI view. At the moment my project won't run with: </p>
  
  <pre><code>'unowned' may only be applied to class and class-bound protocol types, not 'AuthenticateView'
  </code></pre>
  
  <p>and </p>
  
  <pre><code>Value of type 'AuthenticateView' has no member 'present'
  </code></pre>
  
  <p>any help would be much appreciated. Thank you! </p>
  
  <p>Here's my code inside AuthenticateView.swift </p>
  
  <pre><code>func Authenticate(completion: @escaping ((Bool) -&gt; ())){
  
      //Create a context
      let authenticationContext = LAContext()
      var error:NSError?
  
      //Check if device have Biometric sensor
      let isValidSensor : Bool = authenticationContext.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &amp;error)
  
      if isValidSensor {
          //Device have BiometricSensor
          //It Supports TouchID
  
          authenticationContext.evaluatePolicy(
              .deviceOwnerAuthenticationWithBiometrics,
              localizedReason: "Touch / Face ID authentication",
              reply: { [unowned self] (success, error) -&gt; Void in
  
                  if(success) {
                      // Touch / Face ID recognized success here
                      completion(true)
                  } else {
                      //If not recognized then
                      if let error = error {
                          let strMessage = self.errorMessage(errorCode: error._code)
                          if strMessage != ""{
                              self.showAlertWithTitle(title: "Error", message: strMessage)
                          }
                      }
                      completion(false)
                  }
          })
      } else {
  
          let strMessage = self.errorMessage(errorCode: (error?._code)!)
          if strMessage != ""{
              self.showAlertWithTitle(title: "Error", message: strMessage)
          }
      }
  }
  </code></pre>
  
  <pre><code>func errorMessage(errorCode:Int) -&gt; String{
  
      var strMessage = ""
  
      switch errorCode {
  
      case LAError.Code.authenticationFailed.rawValue:
          strMessage = "Authentication Failed"
  
      case LAError.Code.userCancel.rawValue:
          strMessage = "User Cancel"
  
      case LAError.Code.systemCancel.rawValue:
          strMessage = "System Cancel"
  
      case LAError.Code.passcodeNotSet.rawValue:
          strMessage = "Please goto the Settings &amp; Turn On Passcode"
  
      case LAError.Code.touchIDNotAvailable.rawValue:
          strMessage = "TouchI or FaceID DNot Available"
  
      case LAError.Code.touchIDNotEnrolled.rawValue:
          strMessage = "TouchID or FaceID Not Enrolled"
  
      case LAError.Code.touchIDLockout.rawValue:
          strMessage = "TouchID or FaceID Lockout Please goto the Settings &amp; Turn On Passcode"
  
      case LAError.Code.appCancel.rawValue:
          strMessage = "App Cancel"
  
      case LAError.Code.invalidContext.rawValue:
          strMessage = "Invalid Context"
  
      default:
          strMessage = ""
  
      }
      return strMessage
  }
  </code></pre>
  
  <pre><code>func showAlertWithTitle( title:String, message:String ) {
      let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
  
      let actionOk = UIAlertAction(title: "OK", style: .default, handler: nil)
      alert.addAction(actionOk)
      self.present(alert, animated: true, completion: nil)
  }
  </code></pre>