Xcode 找不到 Alamofire,错误:没有这样的模块“Alamofire”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37385275/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 08:50:05  来源:igfitidea点击:

Xcode can't find Alamofire, error: No such module 'Alamofire'

iosxcodeswiftcocoapodsalamofire

提问by Mostafiz Rahman

I'm trying to include Alamofire in my Swift project following the github(https://github.com/Alamofire/Alamofire#cocoapods) instruction.

我正在尝试按照 github( https://github.com/Alamofire/Alamofire#cocoapods) 指令将 Alamofire 包含在我的 Swift 项目中。

I've created a new project, navigated to the project directory and run this command sudo gem install cocoapods. Then I faced following error:

我创建了一个新项目,导航到项目目录并运行此命令sudo gem install cocoapods。然后我遇到了以下错误:

ERROR:  While executing gem ... (Errno::EPERM)
    Operation not permitted - /usr/bin/pod

After searching I managed to install cocoapodsby running this command sudo gem install -n /usr/local/bin cocoapods

搜索后,我设法cocoapods通过运行此命令进行安装sudo gem install -n /usr/local/bin cocoapods

Now I generate a pod file by pod initand edited it this way:

现在我通过pod init以下方式生成一个 pod 文件并对其进行编辑:

# Uncomment this line to define a global platform for your project
# platform :ios, '9.0'


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


  # Pods for Law
    pod 'Alamofire'
  target 'ProjectNameTests' do
    inherit! :search_paths
    # Pods for testing
  end


  target 'ProjectNameUITests' do
    inherit! :search_paths
    # Pods for testing
  end


end

Finally I run pod installto install Alamofire. After that I open the project and import Alamofirestatement gives me following error No such module 'Alamofire'

最后我跑去pod install安装 Alamofire。之后我打开项目和import Alamofire语句给了我以下错误No such module 'Alamofire'

Update-1:Results of pod installis:

更新 1:结果pod install是:

Analyzing dependencies
Downloading dependencies
Using Alamofire (3.4.0)
Generating Pods project
Integrating client project
Sending stats
Pod installation complete! There is 1 dependency from the Podfile and 1 total pod installed.

回答by Diogo Antunes

Open the .xcworkspace not the .xcodeproj

打开 .xcworkspace 而不是 .xcodeproj

回答by Maysam R

go to Product -> Scheme -> Manage Schemes... and check Alamofire truesample imagethis work for me

转到 Product -> Scheme -> Manage Schemes... 并检查 Alamofire true示例图像这对我有用

回答by ciccioska

I suggest you to change your pod file like this below:

我建议你像下面这样更改你的 pod 文件:

# Uncomment this line to define a global platform for your project
platform :ios, '8.0'
# Uncomment this line if you're using Swift
 use_frameworks!

pod 'Alamofire', '~> 3.0' <<<----  Alamofire library is cross beetween projects

target 'NotifyM' do

end

target 'NotifyMTests' do

end

target 'NotifyMUITests' do

end 

Another thing is use_frameworks!you should use this if the project is Objective-Cbased and try to use Swiftpod library.

另一件事是use_frameworks!,如果项目Objective-C基于并尝试使用Swiftpod 库,则应该使用它。

UPDATE: for the new cocoapods version 1.x the shared library should be like this:

更新:对于新的 cocoapods 1.x 版,共享库应该是这样的:

# There are no targets called "Shows" in any Xcode projects
abstract_target 'Shows' do
  pod 'ShowsKit'
  pod 'Fabric'

  # Has its own copy of ShowsKit + ShowWebAuth
  target 'ShowsiOS' do
    pod 'ShowWebAuth'
  end

  # Has its own copy of ShowsKit + ShowTVAuth
  target 'ShowsTV' do
    pod 'ShowTVAuth'
  end
end

as indicated into cocoapods website :http://guides.cocoapods.org/using/the-podfile.html

如 cocoapods 网站所示:http: //guides.cocoapods.org/using/the-podfile.html

回答by Boris Legovic

Sometimes with no reason xcode can't load a module Alamofire. It can happen after a work session, after opening a project. The fix for this is to select a schema -> Alamofire, and run. If the message is "Successful", the schema can be changed back to project and it will work with no problems.

有时 xcode 无缘无故无法加载模块 Alamofire。它可能发生在工作会议之后,打开项目之后。解决方法是选择一个模式 -> Alamofire,然后运行。如果消息为“成功”,则可以将架构更改回项目,并且可以正常工作。

回答by yin seng

you have to clean project and build, before you can import that library.

您必须先清理项目并构建,然后才能导入该库。

回答by yin seng

I suggest that and it's work for me :

我建议这样做,它对我有用:

platform :ios, '8.0'
use_frameworks!

target 'App' do
  pod 'SwiftyJSON', :git => 'https://github.com/SwiftyJSON/SwiftyJSON.git'
  pod 'Alamofire', :git => 'https://github.com/Alamofire/Alamofire.git'

end

After that, run : pod installin your project repository

之后,pod install在您的项目存储库中运行:

回答by Archie

You should tap the Target to select Alamofire and build it once before coding.

您应该点击目标以选择 Alamofire 并在编码之前构建一次。

回答by Anand Nimje

Install this way Pod file

这样安装Pod文件

# Uncomment this line to define a global platform for your project
 platform :ios, '8.0'
# Uncomment this line if you're using Swift
 use_frameworks!

target 'NotifyM' do

pod 'Alamofire', '~> 3.0'

end

target 'NotifyMTests' do

end

target 'NotifyMUITests' do

end