得到“不是公认的Objective-C方法".将Swift桥接到React-Native时 [英] Got "is not a recognized Objective-C method" when bridging Swift to React-Native
问题描述
I'm trying to bridge my React-Native 0.33 code to a super simple Swift method, following this guide but all I'm getting is show:(NSString *)name is not a recognized Objective-C method
.
这是我的代码:
import Foundation
@objc(SwitchManager)
class SwitchManager: NSObject {
@objc func show(name: String) -> Void {
NSLog("%@", name);
}
}
SwitchManagerBridge.h
#import "RCTBridgeModule.h"
@interface RCT_EXTERN_MODULE(SwitchManager, NSObject)
RCT_EXTERN_METHOD(show:(NSString *)name)
@end
SwitchManager-Bridging-Header.h
#import "RCTBridgeModule.h"
然后在我的index.ios.js
文件中,使用import { SwitchManager } from 'NativeModules';
导入SwitchManager并调用SwitchManager.show('One');
.这是发生错误的地方.
Then on my index.ios.js
file I'm importing SwitchManager with import { SwitchManager } from 'NativeModules';
and calling SwitchManager.show('One');
. This is where the error happened.
不确定怎么了.
推荐答案
我整天都在努力解决这个问题.通过将Swift编译器设置为使用旧版版本来解决(XCode 8首选Swift 3),因此在:
I was fighting with this issue all day. Resolved by setting the Swift Compiler to use Legacy versions (XCode 8 is prefers Swift 3), so in:
构建设置>向下滚动到设置为是的"使用旧版Swift语言版本".
Build Settings > Scroll down to 'Use Legacy Swift Language Version' set as Yes.
这篇关于得到“不是公认的Objective-C方法".将Swift桥接到React-Native时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!