title: How to bridge a Swift Promise to React Native
body: <p>I'm integrating an iOS native SDK into React-Native. There's a function called <code>SDK.getCardData</code> which I want to use from RN. My first attempt was to call <code>resolve</code> and <code>reject</code> inside the closure:</p>
  <pre class="lang-swift prettyprint-override"><code>import Foundation
  import SDK
  
  @objc(SwiftComponentManager)
  class SwiftComponentManager: NSObject {
    
    @objc
    func getCardData(_ resolve: RCTPromiseResolveBlock, rejecter reject: RCTPromiseRejectBlock) -&gt; Void {
      let cardId: String = &quot;test&quot;
      let secret: String = &quot;test&quot;
  
      SDK.getCardData(cardId, secret: secret) { (cardData, error) in
        if (error != nil) {
          reject(String(format: &quot;Card data request failed: %@&quot;, error!.localizedDescription))
        } else {
          let pan = cardData!.pan
          let cvv = cardData!.cvv
  
          resolve(String(format: &quot;Card data fetched successfully, pan: %@, cvv: %@&quot;, pan, cvv))
        }
      }
    }
  
    @objc func testMethod() -&gt; Void {
      print(&quot;This Does appear&quot;)
    }
  }
  </code></pre>
  <p>Unfortunately this throws the following error: <code>escaping closure captures non-escaping parameter 'resolve'</code>.</p>
  <p>Second attempt:</p>
  <pre class="lang-swift prettyprint-override"><code>import Foundation
  import SDK
  import Promises
  
  @objc(SwiftComponentManager)
  class SwiftComponentManager: NSObject {
    
    @objc
    func getCardData(_ resolve: RCTPromiseResolveBlock, rejecter reject: RCTPromiseRejectBlock) -&gt; Promise&lt;CardData?&gt; {
      let cardId: String = &quot;test&quot;
      let secret: String = &quot;test&quot;
      let promise = Promise&lt;CardData?&gt;()
  
      SDK.getCardData(cardId, secret: secret) { (cardData, error) in
        if (error != nil) {
          promise.reject(error)
        } else {
          let pan = cardData!.pan
          let cvv = cardData!.cvv
  
          promise.resolve(cardData)
        }
      }
      
      return promise
    }
  
    @objc func testMethod() -&gt; Void {
      print(&quot;This Does appear&quot;)
    }
  }
  
  </code></pre>
  <p>How to call the <code>resolve</code> &amp; <code>reject</code> properly? It is important for the function to return <code>Void</code>, <a href="https://stackoverflow.com/questions/42577511/how-to-bridge-react-native-promise-to-swift">more here</a>.</p>