得到“不是公认的Objective-C方法".将Swift桥接到React-Native时 [英] Got "is not a recognized Objective-C method" when bridging Swift to React-Native

查看:201
本文介绍了得到“不是公认的Objective-C方法".将Swift桥接到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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆