Skip to content

Instantly share code, notes, and snippets.

@carly-lee
Forked from robertjpayne/RCTSwiftBridgeModule.h
Created June 28, 2018 14:12
Show Gist options
  • Save carly-lee/4e3bbe936c4076e56cfd2a6f1c0e770b to your computer and use it in GitHub Desktop.
Save carly-lee/4e3bbe936c4076e56cfd2a6f1c0e770b to your computer and use it in GitHub Desktop.
React Native - Swift Native Modules
#import <Foundation/Foundation.h>
#import "RCTBridgeModule.h"
#define RCT_EXTERN_MODULE(objc_name, objc_supername) \
RCT_EXTERN_REMAP_MODULE(objc_name, objc_name, objc_supername)
#define RCT_EXTERN_REMAP_MODULE(js_name, objc_name, objc_supername) \
objc_name : objc_supername \
@end \
@interface objc_name (RCTExternModule) <RCTBridgeModule> \
@end \
@implementation objc_name (RCTExternModule) \
RCT_EXPORT_MODULE(js_name)
#define RCT_EXTERN_METHOD(method) \
RCT_EXTERN_REMAP_METHOD(, method)
#define RCT_EXTERN_REMAP_METHOD(js_name, method) \
- (void)__rct_export__##method { \
__attribute__((used, section("__DATA,RCTExport"))) \
__attribute__((__aligned__(1))) \
static const char *__rct_export_entry__[] = { __func__, #method, #js_name }; \
}
import Foundation
@objc(SwiftReactModule)
class SwiftReactModule: NSObject {
@objc func printMessage(message: String!) {
println("SwiftReactModule::printMessage => \(message)")
}
}
#import "RCTSwiftBridgeModule.h"
@interface RCT_EXTERN_MODULE(SwiftReactModule, NSObject)
RCT_EXTERN_METHOD(printMessage:(NSString *)message)
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment