首页 > 解决方案 > 没有这样的模块 RealmSwift

问题描述

这不是一个重复的问题。我已经使用领域很长时间了。最近我收到“没有这样的模块 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

标签: swiftxcoderealmswift4.2

解决方案


由于我重复了您的问题,因此这更像是一个故障排除步骤而不是直接答案。

您已经使用 Realm 一段时间了,所以您知道这一点,但对于未来的读者,请确保您使用 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

这似乎在我的项目中工作。

哦-为了完整起见,我也遇到过一次,解决方案是

将 RealmSwift.framework 的父路径(即包含目录)添加到您的框架搜索路径中。


推荐阅读