Aar*_*ron 32 xcode ios cocoapods swift alamofire
我正在使用Xcode 8.0 GM.我创建了一个默认的单视图应用程序,我的部署目标设置为9.0.
在我的Podfile中,我瞄准了Swift 3分支的前沿:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '9.0'
use_frameworks!
target 'MyProject' do
pod 'Alamofire', :git => 'https://github.com/Alamofire/Alamofire.git', :branch => 'swift3'
end
Run Code Online (Sandbox Code Playgroud)
我跑了pod install,得到...... Installing Alamofire (4.0.0-beta.2)太棒了,没问题.我打开MyProject.xcworkspace.
弹出:
我以后不能打,因为它告诉我:
Xcode 8将无法构建目标"Alamofire",并且在转换此目标中的Swift源代码之前,某些编辑功能将无法正常运行.
这不好,我想建立它.所以我点击"转换".它给了我选择:
那就是我想要的,Swift 3.看起来不错,我点击"下一步".
它默认为这3个选定目标.好的,我接下来打了.
神的圣名是什么......
我想在swift3针对iOS 9.0的Xcode 8,Swift 3项目中使用Alamofire的前沿分支.我哪里出错了,怎么才能让这个工作?FWIW我试图使用Alamofire的Swift 2.3分支时遇到一堆错误,所以我知道这是我做错了.
我能够让它工作:
更新:
# Uncomment this line to define a global platform for your project
# platform :ios, '9.0'
target 'PROJECT NAME HERE' do
# Comment this line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!
pod 'Alamofire',
:git => 'https://github.com/Alamofire/Alamofire.git',
:branch => 'swift3'
end
Run Code Online (Sandbox Code Playgroud)
pod更新Alamofire
获取请求时有一些更改:
旧:
Alamofire.request(URL_NAME_HERE, withMethod: .get).responseJSON { response in
//Code here.
}
Run Code Online (Sandbox Code Playgroud)
新:
Alamofire.request(URL_NAME_HERE, method: .get).responseJSON { response in
//Code here.
}
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助.
您应该立即使用master分支,因为swift3分支已在那里合并.此外,Xcode Migrator显示许多错误是正常的.它正在编写代码,认为它是一个传统的Swift版本,但由于它已经在Swift 3.0中,因此错误是可以预期的.最后,Xcode要求您转换为现代Swift语法可能是因为您没有使用最新版本的Cocoapods来安装Alamofire.
NB:虽然Cocoapods告诉你使用的事件gem install cocoapods --pre,我更喜欢使用gem update cocoapods --pre.否则,较旧版本的Cocoapods会保留并在使用时仍然使用pod update.检查您正在使用的版本pod --version.