我正在尝试按照 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.
打开 .xcworkspace 而不是 .xcodeproj
有时 xcode 无缘无故无法加载 Alamofire 模块。它可能发生在工作会议之后、打开项目之后。解决此问题的方法是选择一个 schema -> Alamofire,然后运行。如果消息为“成功”,则可以将架构更改回项目,并且它将正常工作。
我建议你像下面这样更改你的 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
您必须清理项目并构建,然后才能导入该库。
这样安装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
我建议这样做,这对我有用:
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
2021 M1 用户
根据:https://developer.apple.com/forums/thread/123614?answerId=683594022#683594022
它对我有用希望它对你有用。
经过大量努力和上面提供的所有解决方案。我已经修复了 Xcode 13.0:
用于模拟器: 前往:
- Build settings -> EXCLUDED_ARCHS = arm64
- Build settings -> VALID_ARCHS = arm64e armv7 armv7s arm64 x86_64
用于 Realm 设备: 前往:
- Build settings -> EXCLUDED_ARCHS =
- Build settings -> VALID_ARCHS = arm64e armv7 armv7s arm64
您应该点击 Target 选择 Alamofire 并在编码之前构建一次。
使用 Cocoapods 包含依赖项时,请始终打开您的 .xcworkspace
use_frameworks!
$(inherited)
。现在尝试干净的构建。