Always get build error : No such module 'Alamofire'

Always get build error : No such module 'Alamofire'

我按照 github

Alamofire 的说明进行操作

我创建了一个名为 cocoapods-test 的 xcode 项目并关闭了它。

我转到项目文件夹 运行 pod init 命令生成一个 Podfile。然后我在 Podfile 中添加了以下代码:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!

pod 'Alamofire', '~> 3.0'

然后,我 运行 命令 pod install,这是 终端中的结果:

Updating local specs repositories

CocoaPods 1.0.0.beta.6 is available.
To update use: `gem install cocoapods --pre`
[!] This is a test version we'd love you to try.

For more information see http://blog.cocoapods.org
and the CHANGELOG for this version http://git.io/BaH8pQ.

Analyzing dependencies
Downloading dependencies
Installing Alamofire (3.3.0)
Generating Pods project
Integrating client project

[!] Please close any current Xcode sessions and use `cocoapods-test.xcworkspace` for this project from now on.
Sending stats
Pod installation complete! There is 1 dependency from the Podfile and 1 total pod installed.

然后,在我的项目文件夹中有一个名为 cocoapods-test.xcworkspace 的新文件。我双击它再次打开我的 xcode,我可以看到 Alamofire 模块。

然后,我打开了我项目的 ViewController class 和 import Alamofire 。但无论我清理和构建多少次,我总是得到错误 No such module 'Alamofire'。这是屏幕截图:

为什么我按照说明一步一步的做,还是会出现这个问题?

(我正在使用 XCode 7.2.1Swift 2.1.1Alamofire 3.3.0

=======更新========

我尝试了@LK Yeung 的回答,取消注释 import Alamofire,然后清理并再次构建,我从 Alarmofire 得到了一堆编译器错误:

您还需要将库添加到 'the Link Binary With Libraries' 部分

使用库前需要编译成功一次工程

注释导入 Alamofire -> 构建 -> 取消注释导入 Alamofire

您可以尝试像下面这样输入 pod 'Alamofire', '~> 3.0'。又是运行pod install

target 'yourtarget' do
     pod 'Alamofire', '~> 3.0'
end

我遇到了完全相同的问题。请确保您使用的是 Xcode 7.3 并使用 Swift 2.2。

您可以使用 xcrun swift -version 检查您的 Swift 版本。将 Xcode 更新到 7.3 应该也会自动更新 Swift.

更新 Xcode 为我解决了这个问题。

我遇到了同样的问题,原因是我安装了错误的alamofire版本。

我正在使用 Xcode 7.3,swift 2.2,所以 alamofire 3.0 对我有用

使用@Michal 提到的这些步骤删除库

Remove or uninstall library previously added : cocoapods

然后在你的 pod 文件中

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

platform :ios, ‘9.3’  <-- your target version

use_frameworks!

target ’<your target name>’ do
    pod 'Alamofire', '~> 3.0’

end

尝试安装最新更新的 alamofire,并检查你是否使用最新的 alamofire xcode 支持。

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '10.0'
use_frameworks!

target '<Your Target Name>' do
    pod 'Alamofire', '~> 4.4'
end

在你的 podfile 上试试上面的 alamofire

确保你打开了 "project_name".xcworkspace 而不是 "project_name".xcodeproj 。正如你正在处理 pods 所有已安装的 pod 将仅在您的 .xcworkspace 项目文件中可用。

如果您手动安装 Alamofire(或任何其他框架),请确保您的构建配置在父项目和子项目之间匹配。例如,如果您项目中的构建配置名为 'Development',但 Alamofire 的名为 'Debug',您将收到 'no such module' 错误。

没有这样的模块'Alamofire'错误

因为你还没有在你的 pod 文件中安装 Alamofire 打开 Podfile 并添加此行

pod 'Alamofire'

double-check 在 Podfile 中,如果这行已经写好了,那么就不需要写了。然后只需更新 pod 文件

为了更新你的 pod,打开你的 Podfile 到终端并拨号

pod update

按照这个序列

➼ 打开终端,转到项目文件夹并 运行 这些命令:

sudo gem install cocoapods -n /usr/local/bin
pod install

➼ 转到这个 link 并清除派生数据文件夹:

~/Library/Developer/Xcode/DerivedData

➼ 然后打开项目“xcworkspace”文件并按下:

Command + Shift + K 

➼ 然后:

Command + B 

现在应该可以了

干杯!