title: How to capture local variable inside an async closure in Swift?
body: <p>I have the following code in Swift 5.5 and iOS 15</p>
  <pre><code>func getReviewIds() {
      
      var reviewIds: [Int] = []
      
      Task {
          let ids = await getReviewIdsFromGoogle()
          reviewIds.append(contentsOf: ids)
      }
      
      print(&quot;outside&quot;)
  }
  
  func getReviewIdsFromGoogle() async -&gt; [Int] {
      await withUnsafeContinuation { continuation in
          DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) {
              continuation.resume(returning: [1,2,3])
          }
      }
  }
  </code></pre>
  <p>I get an error in <code>getReviewIdsFromGoogle</code> function on the following line:</p>
  <pre><code> reviewIds.append(contentsOf: ids)
  
  Mutation of captured var 'reviewIds' in concurrently-executing code
  </code></pre>
  <p>I know that I can make the <code>getReviewIdsFromGoogle</code> an <code>async</code> function instead of using the <code>async</code> closure, but how can I solve this using the closure.</p>