我使用以下命令创建了第一个react-native 应用程序.

react-native init PropertyFinder

这在Objective-C年为ios创建了一个项目.问题是我不知道Objective-C,但我在Swift上工作.

gist展示了如何将react组件链接到swift项目.

推荐答案

这个excellent post帮助我解决了这个问题.

解决方案

  1. 添加桥接头
#import "RCTBridgeModule.h"
#import "RCTBridge.h"
#import "RCTEventDispatcher.h"
#import "RCTRootView.h"
#import "RCTUtils.h"
#import "RCTConvert.h"
  1. 添加AppDelegate.敏捷的
var bridge: RCTBridge!

  func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.
    /**
     * Loading JavaScript code - uncomment the one you want.
     *
     * OPTION 1
     * Load from development server. Start the server from the repository root:
     *
     * $ npm start
     *
     * To run on device, change `localhost` to the IP address of your computer
     * (you can get this by typing `ifconfig` into the terminal and selecting the
     * `inet` value under `en0:`) and make sure your computer and iOS device are
     * on the same Wi-Fi network.
     */

    let jsCodeLocation = NSURL(string: "http://localhost:8081/index.ios.bundle?platform=ios&dev=true")

    /**
     * OPTION 2
     * Load from pre-bundled file on disk. The static bundle is automatically
     * generated by "Bundle React Native code and images" build step.
     */

    // jsCodeLocation = NSBundle.mainBundle().URLForResource("main", withExtension: "jsbundle")

    let rootView = RCTRootView(bundleURL:jsCodeLocation as URL!, moduleName: "PropertyFinder", initialProperties: nil, launchOptions:launchOptions)

    self.bridge = rootView?.bridge

    self.window = UIWindow(frame: UIScreen.main.bounds)
    let rootViewController = UIViewController()

    rootViewController.view = rootView

    self.window!.rootViewController = rootViewController;
    self.window!.makeKeyAndVisible()

    return true
  }
  1. 删除AppDelegate.hAppDelegate.m和主文件.

  2. 清理并构建你的项目.

React-native相关问答推荐

类似Snapchat的Reaction Native筛选器

ios 中节列表中的scrollToLocation 不起作用.在 Android 上,列表滚动回索引 0,但在 ios 上不会发生同样的情况

RTK 查询显示互联网何时关闭?

React Native Axios 通过数组的键过滤

使用react native 杀死应用程序后蓝牙仍处于活动状态

如何将谷歌反向地理编码与 React Native Expo 结合使用?

React 从 babel 6 到 babel 7 的原生升级

React-native android 样式化 textInput

Property body[41] of BlockStatement expected node to be of a type ["Statement"] but instead got "AssignmentExpression"

FlatList contentContainerStyle -> justifyContent: 'center' 导致滚动问题

是否可以使用react-native 创建 Android Wear 应用程序

try 添加包时出现错误duplicate entry:com/google/android/gms/internal/zzble.class

背景图像在react中不起作用

iOS 模拟器如何确认alert信息

将 React Native 升级到 0.60-RC2 后找不到库libjsc.so

使用 Jest 的 react-navigation 测试组件

React.createClass vs. ES6 箭头函数

如何更改键盘上的 return按钮?

如何在react-native中显示toast消息

在 react-native 中使用捏拉zoom 的可滚动图像