3

我正在创建一个应用程序,我需要导入“Alamofire”和“ObjectMapper”来调用服务 API REST。问题是我无法以任何方式导入这两个 pod 中的任何一个。

为了简化程序,我创建了一个只有一个 viewController 的项目。在其中,我在开头进行了导入(例如:import Alamofire),并且我有一个这种类型的 podfile:

Source 'https://github.com/CocoaPods/Specs.git'
Platform: ios, '10 .0 '
Use_frameworks!

Target 'TestAlamofire'
Pod 'AlamofireDomain'
Pod 'ObjectMapper'

在“构建设置”中,我的框架搜索路径是:

"$ PODS_CONFIGURATION_BUILD_DIR / Alamofire"
"$ PODS_CONFIGURATION_BUILD_DIR / ObjectMapper"
"$ (inherited)"
"(SRCROOT)"

如果我删除 viewController 中的“import AlamofireDomain”或“import Objectmapper”,程序会编译并执行,但如果我添加它,则会出现错误“no such module ...”。

你认为错误在哪里?你给我什么解决方案?

该应用程序使用 Swift 3.0、Xcode 8.2.1 和 IOS 10 开发。

4

2 回答 2

2

我认为您Podfile缺少doend是您在其中添加所需 pod 的关键字

所以尝试做这样的事情来解决它

source 'https://github.com/CocoaPods/Specs.git'
use_frameworks!

platform :ios, '10.0'

target 'TestAlamofire' do
    pod 'Alamofire', '~> 4.4'
   pod 'ObjectMapper', '~> 2.2'
end

另外,由于您使用的是豆荚,我猜您已经通过以下方式安装了它们

  • 打开终端
  • 打字cd然后按空格
  • 然后拖放包含Podfile然后点击返回的文件夹
  • 然后输入pod install并回车

下载完成后打开工作区,扩展名为 .xcworkspace 的文件

您还可以查看Cocoapods 指南

于 2017-03-13T23:08:33.487 回答
2

我为解决问题所采取的步骤:

- 将我的 Podfile 更改为:

source 'https://github.com/CocoaPods/Specs.git'
use_frameworks!

platform :ios, '10.0'

target 'TestAlamofire' do
    pod 'Alamofire', '~> 4.4'
    pod 'AlamofireDomain', '~> 4.1'
    pod 'ObjectMapper', '~> 2.2'
end
  • 安装 Xcode 8.3 因为我安装了 Almofire 3.1 而不是 swift 3 的 4.1

  • 当我们执行“import Alamofire”时,它会返回错误,但如果我们单击 cmd + B,项目将与我们所做的导入一起重建。

  • 打开扩展名为“xcworkspace”而不是“xcodeproj”的文件

于 2017-03-14T11:32:18.780 回答