Xcode: 没有这样的模块 'Alamofire'

Xcode: No Such Module 'Alamofire'

我一直收到错误

No Such Module 'Alamofire'

在我的Xcode项目swift文件中使用import Alamofire;该文件位于项目中的单独模块中。

我试过以下;

然而,当我打开 swift 文件的检查器 window 时,Target Membership 已勾选主应用程序和模块框。

当我取消选中文件所在的模块时,在我的 seperateModuleTests 文件中我无法使用 swift 文件中使用的 classes,因为我得到错误;

Use of undeclared type

&&

Use of unresolved identifier 'ClassName'

似乎当我取消选中用于测试的 class 的 swift 文件的目标成员时,seperateModuleTests 无法识别 class来自 swift 文件的 es。但是当我检查 swift 文件的目标成员身份是否是单独模块的一部分时,我得到了原始错误。

任何人都可以帮助我了解为什么会发生这种情况以及我该如何解决?

我认为您在测试目标

中缺少添加 Alamofire
# Uncomment the next line to define a global platform for your project
platform :ios, '9.0'

target 'AppName' do
  # Comment the next line if you're not using Swift and don't want to use dynamic frameworks
  use_frameworks!

  # Pods for AppName
  pod 'SwiftyJSON'
  pod 'Alamofire', '4.4.0'

  target 'AppNameTests' do
    inherit! :search_paths
    pod 'Alamofire', '4.4.0'
  end

  target 'AppNameUITests' do
    inherit! :search_paths
     pod 'Alamofire', '4.4.0'
  end

end

更好

您还可以对您的目标

的所有 pods 进行配置
# Uncomment this line to define a global platform for your project
platform :ios, '8.2'
# Uncomment this line if you're using Swift
use_frameworks!

# Define main pods.
def main_pods
    #Your common pods here
    pod 'Alamofire', '4.4.0'
end

target 'AppName' do
    main_pods
    #add here other pods specific for this target
end


target 'AppNameTests' do
    main_pods
    #add here other pods specific for this target
end

target 'AppNameUITests' do
    main_pods
    #add here other pods specific for this target
end

希望对您有所帮助

运行 清理:产品 > 清理然后构建。

如果这不起作用。这是如何使用的?是你自己的代码,还是需要你有 AlamoFire 的另一个模块?