Example of calling swift code from RN
This commit is contained in:
parent
1a9884e0e9
commit
151ed6d78b
12 changed files with 86 additions and 6 deletions
31
ios/Native/Application/Services/TestingService.swift
Normal file
31
ios/Native/Application/Services/TestingService.swift
Normal file
|
@ -0,0 +1,31 @@
|
|||
//
|
||||
// TestingService.swift
|
||||
// RNPlayground
|
||||
//
|
||||
// Created by Artur Gurgul on 03/08/2025.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import React
|
||||
|
||||
@objc(TestingServiceModule)
|
||||
class TestingServiceModule: NSObject {
|
||||
|
||||
@objc
|
||||
func greet(_ name: String,
|
||||
resolver resolve: @escaping RCTPromiseResolveBlock,
|
||||
rejecter reject: @escaping RCTPromiseRejectBlock) {
|
||||
let message = "Hello, \(name)! From Swift."
|
||||
resolve(message)
|
||||
}
|
||||
|
||||
@objc
|
||||
func constantsToExport() -> [AnyHashable: Any]! {
|
||||
return ["greeting": "Hello from Swift"]
|
||||
}
|
||||
|
||||
@objc
|
||||
static func requiresMainQueueSetup() -> Bool {
|
||||
return false
|
||||
}
|
||||
}
|
17
ios/Native/Application/Services/TestingServiceModuleBridge.m
Normal file
17
ios/Native/Application/Services/TestingServiceModuleBridge.m
Normal file
|
@ -0,0 +1,17 @@
|
|||
//
|
||||
// TestingServiceModuleBridge.m
|
||||
// RNPlayground
|
||||
//
|
||||
// Created by Artur Gurgul on 03/08/2025.
|
||||
//
|
||||
|
||||
#import <React/RCTBridgeModule.h>
|
||||
|
||||
// This tells React Native about the Swift class
|
||||
@interface RCT_EXTERN_MODULE(TestingServiceModule, NSObject)
|
||||
|
||||
RCT_EXTERN_METHOD(greet:(NSString *)name
|
||||
resolver:(RCTPromiseResolveBlock)resolve
|
||||
rejecter:(RCTPromiseRejectBlock)reject)
|
||||
|
||||
@end
|
Loading…
Add table
Add a link
Reference in a new issue