ReactNative XCode编译问题
MacOS Monterey 12.6.1 + XCode 14.1 (14B47b) + 模拟器 iPhone11 ios13.4
启动步骤
- 打开终端,
yarn start
启动Metro服务 - 打开XCode,打开项目中的ios文件夹下的
.xcworkspace
项目文件 - 点击 ▶️ 编译运行
问题及处理方法
- 问题:
myApp/ios/Pods/Charts/Source/Charts/Data/Implementations/Standard/ChartDataSet.swift:532:1 Unavailable instance method 'replaceSubrange(_:with:)' was used to satisfy a requirement of protocol 'RangeReplaceableCollection'
- 解决:
// MARK: RangeReplaceableCollection
extension ChartDataSet: RangeReplaceableCollection 方法里补充
public func replaceSubrange<C>(_ subrange: Swift.Range<Int>, with newElements: C) where C :
Collection, ChartDataEntry == C.Element {
}
- 问题:
myApp/ios/bundle/assets: No such file or directory
- 解决:
在ios文件夹下新建 bundle/assets 路径及对应文件夹
- 问题:
myApp/ios/bundle/main.jsbundle: No such file or directory
- 解决:
- 在package.json文件新增命令
"scripts": {
......
"bundle-ios":"node node_modules/react-native/local-cli/cli.js bundle --entry-file index.js --platform ios --dev false --bundle-output ios/bundle/main.jsbundle --assets-dest ios/bundle"
},
- 终端运行
yarn bundle-ios
- XCode重新点击 ▶️ 编译运行