在 Xcode 中从手动安装转向通过 Cocoapods 使用 Realm
Move from manual install to use Realm through Cocoapods in Xcode
我目前在我的一个项目中使用 Realm,我在其中手动安装了它。一切正常,直到我将 Xcode 从 10.1 更新到 10.2。现在我不断收到以下错误。
Module compiled with Swift 4.2 cannot be imported by the Swift 5.0 compiler: /Users/userName/MyApp/RealmSwift.framework/Modules/RealmSwift.swiftmodule/i386.swiftmodule
我相信这与以下事实有关:当我尝试用为 Xcode 10.2 编译的最新 Realm
替换项目中的 Realm frameworks
时,Xcode 不复制文件,即使选中了 如果需要复制文件 选项,它也只是引用它们。
无论如何,我现在想尝试使用 Realm
到 Cocoapods
来消除每次更新 Xcode 时出现的此类问题,所以我的问题是...
我需要在 Xcode 中更改什么才能从手动安装转变为通过 Cocoapods 使用 Realm?
我在框架搜索路径中需要什么?
我需要删除 Run Script Phase
bash "${BUILT_PRODUCTS_DIR}/${FRAMEWORKS_FOLDER_PATH}/Realm.framework/strip-frameworks.sh"?
我的 Pod 文件需要什么?我更想知道如何将 Realm
合并到我的 WatchApp Extension
中,因为我在文档中找不到任何信息。
这是我的 Pod 文件现在的样子。
Pod 文件
#platform :ios, '9.3'
target 'MyApp' do
use_frameworks!
# Pods for MyApp
pod 'Firebase/Core'
pod 'NVActivityIndicatorView'
target 'MyAppTests' do
inherit! :search_paths
end
target 'MyAppUITests' do
inherit! :search_paths
end
end
target 'MyApp Watch App' do
use_frameworks!
end
target 'MyApp Watch App Extension' do
use_frameworks!
end
仅供参考 - 我已经在我的项目中使用 Cocoapods 但还没有用于 Realm
。另外,我在这个项目中将 Realm
用于 iOS
和 WatchApp Extension
。
如果您已经拥有由 cocoapods 创建的工作区,则无需修改项目设置,当您将新的 pod 添加到 podfile 时,cocoapods 会自动处理将其正确链接到您的项目。
只需删除手动添加的 Realm 框架文件,删除包含 "${BUILT_PRODUCTS_DIR}/${FRAMEWORKS_FOLDER_PATH}/Realm.framework/strip-frameworks.sh"
的自定义 运行 脚本构建阶段,然后 运行 pod update
就可以了.
至于原刊
Module compiled with Swift 4.2 cannot be imported by the Swift 5.0 compiler: /Users/userName/MyApp/RealmSwift.framework/Modules/RealmSwift.swiftmodule/i386.swiftmodule
,使用预编译框架时,需要等框架开发者更新Swift5的预编译版本(或者你项目要切换到的最新版本)后才能使用.
由于 cocoapods 在您自己的机器上从源代码编译所有依赖项,因此不会出现 Swift 编译器版本不兼容的问题,您甚至可以控制每个项目具体使用哪个 Swift 版本podfile.
我目前在我的一个项目中使用 Realm,我在其中手动安装了它。一切正常,直到我将 Xcode 从 10.1 更新到 10.2。现在我不断收到以下错误。
Module compiled with Swift 4.2 cannot be imported by the Swift 5.0 compiler: /Users/userName/MyApp/RealmSwift.framework/Modules/RealmSwift.swiftmodule/i386.swiftmodule
我相信这与以下事实有关:当我尝试用为 Xcode 10.2 编译的最新 Realm
替换项目中的 Realm frameworks
时,Xcode 不复制文件,即使选中了 如果需要复制文件 选项,它也只是引用它们。
无论如何,我现在想尝试使用 Realm
到 Cocoapods
来消除每次更新 Xcode 时出现的此类问题,所以我的问题是...
我需要在 Xcode 中更改什么才能从手动安装转变为通过 Cocoapods 使用 Realm?
我在框架搜索路径中需要什么?
我需要删除
Run Script Phase
bash "${BUILT_PRODUCTS_DIR}/${FRAMEWORKS_FOLDER_PATH}/Realm.framework/strip-frameworks.sh"?我的 Pod 文件需要什么?我更想知道如何将
Realm
合并到我的WatchApp Extension
中,因为我在文档中找不到任何信息。
这是我的 Pod 文件现在的样子。
Pod 文件
#platform :ios, '9.3'
target 'MyApp' do
use_frameworks!
# Pods for MyApp
pod 'Firebase/Core'
pod 'NVActivityIndicatorView'
target 'MyAppTests' do
inherit! :search_paths
end
target 'MyAppUITests' do
inherit! :search_paths
end
end
target 'MyApp Watch App' do
use_frameworks!
end
target 'MyApp Watch App Extension' do
use_frameworks!
end
仅供参考 - 我已经在我的项目中使用 Cocoapods 但还没有用于 Realm
。另外,我在这个项目中将 Realm
用于 iOS
和 WatchApp Extension
。
如果您已经拥有由 cocoapods 创建的工作区,则无需修改项目设置,当您将新的 pod 添加到 podfile 时,cocoapods 会自动处理将其正确链接到您的项目。
只需删除手动添加的 Realm 框架文件,删除包含 "${BUILT_PRODUCTS_DIR}/${FRAMEWORKS_FOLDER_PATH}/Realm.framework/strip-frameworks.sh"
的自定义 运行 脚本构建阶段,然后 运行 pod update
就可以了.
至于原刊
Module compiled with Swift 4.2 cannot be imported by the Swift 5.0 compiler: /Users/userName/MyApp/RealmSwift.framework/Modules/RealmSwift.swiftmodule/i386.swiftmodule
,使用预编译框架时,需要等框架开发者更新Swift5的预编译版本(或者你项目要切换到的最新版本)后才能使用.
由于 cocoapods 在您自己的机器上从源代码编译所有依赖项,因此不会出现 Swift 编译器版本不兼容的问题,您甚至可以控制每个项目具体使用哪个 Swift 版本podfile.