title: React Native Swift callback
body: <p>I would like to send a String to a Swift-implemented module from React Native and then just get a String result as a callback from the native module for further use.</p>
  
  <p>Here's what i've got:</p>
  
  <pre><code>//HelloWorldModule.m
  
  #import "RCTBridgeModule.h"
  
  @interface RCT_EXTERN_MODULE(HelloWorldModule, NSObject)
  
  RCT_EXTERN_METHOD(sayHelloWorld:(NSString *)name callback:(RCTResponseSenderBlock *)successCallback)
  
  @end
  </code></pre>
  
  <p>Alongside the Swift implementation:</p>
  
  <pre><code>//  HelloWorldModule.swift
  
  import Foundation
  import UIKit
  import AVFoundation
  
  @objc(HelloWorldModule)
  class HelloWorldModule: NSObject {
  
    @objc func sayHelloWorld(name: String,  callback successCallback: RCTResponseSenderBlock) {
      NSLog("Log from Swift: \(name)")
      successCallback([name])
    }
  }
  </code></pre>
  
  <p>and finally whatever goes into the ReactNative part:</p>
  
  <pre><code>// requiring the Swift module in React Native
  var HelloWorldModule = require('react-native').NativeModules.HelloWorldModule;
  
  ...
  
  // using it somewhere in the render function
  
  render: function() {
         return (
          &lt;Text&gt;
            Hello World Module answers: {this.hwmExt("Jadzia Dax")}
          &lt;/Text&gt;
         );
  },
  
  hwmExt: function(name) {
      return HelloWorldModule.sayHelloWorld(name, function(result) {
         var hwAnswer = "swiftCB: " + result;
         console.log(hwAnswer);
         return hwAnswer;
      });
  }
  </code></pre>
  
  <p>The line <code>console.log(hwAnswer);</code> prints out what I expect it to be <code>swiftCB: Jadzia Dax</code> but the result is not being passed over? Did I do something wrong in the method definition in Swift as I always get undefined? Somehow got blind over this problem :/ React Native Swift module callbacks are unfortunately not covered in the RN docs, too.</p>