我试图按照github(https://github.com/Alamofire/Alamofire#cocoapods)指令将Alamofire包含在我的Swift项目中。
我创建了一个新项目,导航到项目目录并运行此命令sudo gem install cocoapods
。然后我遇到了以下错误:
ERROR: While executing gem ... (Errno::EPERM)
Operation not permitted - /usr/bin/pod
搜索后,我设法通过运行此命令cocoapods
sudo gem install -n /usr/local/bin cocoapods
现在我按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
最后我运行pod install
来安装Alamofire。之后我打开了项目,import Alamofire
语句给了我以下错误No such module 'Alamofire'
更新-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.
答案 0 :(得分:9)
打开.xcworkspace而不是.xcodeproj
答案 1 :(得分:4)
答案 2 :(得分:1)
我建议您更改下面的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
另一件事是use_frameworks!
如果项目基于Objective-C
,您应该使用此功能,并尝试使用Swift
pod库。
更新:对于新的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
如cocoapods网站所示:http://guides.cocoapods.org/using/the-podfile.html
答案 3 :(得分:1)
有时没有理由xcode无法加载模块Alamofire。它可以在工作会话之后,在打开项目之后发生。解决此问题的方法是选择架构 - &gt; Alamofire,然后跑。如果消息是&#34;成功&#34;,则可以将架构更改回项目,并且它可以正常工作。
答案 4 :(得分:1)
在导入该库之前,您必须清理项目并进行构建。
答案 5 :(得分:0)
您应该点击目标选择Alamofire并在编码之前构建一次。
答案 6 :(得分:0)
以这种方式安装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
答案 7 :(得分:0)
我建议并且它对我有用:
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
之后,在项目资源库中运行pod install
答案 8 :(得分:0)
当使用 Cocoapods 包含依赖项时,请始终打开您的 .xcworkspace
use_frameworks!
$(inherited)
。现在尝试一个干净的构建。