title: How can I use async/await with SwiftUI in Swift 5.5?
body: <p>I have been testing the async/await functionality previewed in the Swift 5.5 release, but I am unable to collect the results from an async function and display them using SwiftUI. Here is my code:</p>
  <pre class="lang-swift prettyprint-override"><code>import SwiftUI
  
  struct AsyncTestView: View {
      @State var text: String?
  
      // Async function
      func asyncGetText() async -&gt; String {
          Thread.sleep(forTimeInterval: 10)
          return &quot;My text&quot;
      }
      
      // Stores the result of async function
      func fetchText() async {
          let text = await asyncGetText()
          DispatchQueue.main.async {
              self.text = text
          }
      }
      
      var body: some View {
          Text(text ?? &quot;Loading&quot;)
              .onAppear(perform: fetchText)
      }
  }
  </code></pre>
  <p>This results in the following error:</p>
  <blockquote>
  <p>'async' call in a function that does not support concurrency<br>
  Add 'async' to function 'fetchText()' to make it asynchronous</p>
  </blockquote>
  <p>Adding <code>async</code> to the <code>fetchText()</code> function then results in the following error on the <code>.onAppear()</code> function:</p>
  <blockquote>
  <p>Invalid conversion from 'async' function of type '() async -&gt; ()' to synchronous function type '() -&gt; Void'</p>
  </blockquote>
  <p>In <a href="https://peterfriese.dev/async-await-in-swiftui/" rel="noreferrer">this article</a>, they use the <code>@asyncHandler</code> tag to annotate the <code>fetchText</code> function, however this results in the warning: <code>'@asyncHandler' has been removed from the language'</code>.</p>