title: How to wait for LAContext.evaluatePolicy result in a simple terminal app
body: <p>First and foremost I am very new to swift, and it is not my primary language. I have some difficulty to understand the concurrent constructs, and some are not yet available (until macOs 12 is released).</p>
  <p>So I'd like the command line app to use the touchId of the laptop to access some data. I found numerous examples of the <a href="https://developer.apple.com/documentation/localauthentication/lacontext/1514176-evaluatepolicy" rel="nofollow noreferrer"><code>LAContext.evaluatePolicy</code></a> call. However they seem all related to GUI apps (either in macOs or on iOS).</p>
  <p>My problem is that I am working on a terminal app and the <code>evaluatePolicy</code> is evaluate on a <em>private queue</em> while the <em>main</em> thread finishes without leaving the time to actually show the authentication dialog.</p>
  <p>I've tried to create a very simple reproducer, purely in swift. (But my terminal app has some code in C that calls the swift method).</p>
  <pre><code>import LocalAuthentication
  
  @_cdecl(&quot;authenticate&quot;)
  public func authenticateUser() {
      let context = LAContext()
  
      context.localizedFallbackTitle = &quot;Please use your password&quot;
      context.localizedCancelTitle = &quot;Abort&quot;
  
      var authorizationError: NSError?
      let permissions = context.canEvaluatePolicy(
              LAPolicy.deviceOwnerAuthentication, // TouchId or passcode
              error: &amp;authorizationError
      )
  
      if permissions {
          let biometry = context.biometryType
          if (biometry != LABiometryType.touchID) {
              print(&quot;TouchID not available&quot;)
              return
          }
  
          let reason = &quot;Identify yourself!&quot;
          print(reason)
  
          context.evaluatePolicy(
                  LAPolicy.deviceOwnerAuthentication,
                  localizedReason: reason
          ) { (success: Bool, error: Error?) -&gt; Void in
                  if success {
                      print(&quot; You may enter&quot;)
                  } else {
                      print(&quot; Authentication failed&quot;)
                      print(error?.localizedDescription ?? &quot;Failed to authenticate&quot;)
                  }
          }
  
          // &lt;-------- block here
      } else {
          let ac = &quot;Touch ID not available, Or Your device is not configured for Touch ID.&quot;
          print(ac)
      }
  }
  
  authenticateUser()
  </code></pre>
  <p>In this code snippet, I'd like the code to block to wait on the <code>evaluatePolicy</code> result. Via its reply completion handler or else.</p>
  <p>I have tried to use <code>DispatchQueue.main.async</code> but this doesn't work, so I ultimately didn't do it correctly. Also I have tried using await/async, but <code>swiftc</code> tells me those aren't available on my system (<code>concurrency is only available in macOS 12.0.0 or newer</code>).</p>
  <p>This can be compiled and executed this way:</p>
  <pre class="lang-sh prettyprint-override"><code>$ swiftc main.swift
  $ ./main
  Identify yourself!
  </code></pre>
  <p>Thanks in advance for pointers to make this work.</p>
  <hr />
  <p>Some versions</p>
  <pre class="lang-sh prettyprint-override"><code>$ swiftc --version
  Apple Swift version 5.5 (swiftlang-1300.0.31.1 clang-1300.0.29.1)
  Target: x86_64-apple-darwin20.6.0
  $ sw_vers
  ProductName:    macOS
  ProductVersion: 11.6
  BuildVersion:   20G165
  </code></pre>