这不是一个重复的问题。 我已经使用 Realm 很长时间了。最近我收到“没有这样的模块 RealmSwift”的错误。但这只发生在发布目标方案中,而不是构建目标方案中。是否有任何特殊原因说明为什么它不能仅在发行版中工作?我在很多地方都看到过这个问题,但这些解决方案都不适合我。
我的 podfile 看起来类似于:
# Uncomment the next line to define a global platform for your project
platform :ios, '12.0'
#use_modular_headers!
inhibit_all_warnings!
def shared_pods
pod 'RealmSwift'
end
target ‘************’ do
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!
# Pods for ************
shared_pods
target '************Tests' do
inherit! :search_paths
# Pods for testing
end
end
target '************UITests' do
inherit! :search_paths
# Pods for testing
# shared_pods
end
最佳答案
这更像是一个故障排除步骤,而不是一个直接的答案,因为我重复了你的问题。
您已经使用 Realm 一段时间了,所以您知道这一点,但对于 future 的读者,请确保您使用 RealmSwift 的任何文件都包含
import RealmSwift
我刚刚在一个新项目上尝试了您的 podfile,我也遇到了奇怪的行为。我用以下 5 行替换了你的 podfile,它工作正常。
project 'Realm Test.xcodeproj'
target 'Realm Test' do
use_frameworks!
platform :osx, '10.13'
pod 'RealmSwift'
end
那是一个 macOS 项目,但它同样适用于 iOS 项目。在那个项目上,我取消注释#platform :ios, '12.0'
我觉得是这个问题
inherit! :search_paths
这让目标知道搜索路径但不链接它们。我建议将其更改为
inherit! :complete
这似乎在我的项目中有效。
哦 - 为了完整起见,我也遇到过一次,解决方案是
add the parent path of RealmSwift.framework (i.e., the containing directory) to your framework search paths.
关于swift - 没有这样的模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56716186/