ios Alamofire Xcode 8 Swift 3 导致 786 个编译错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39380939/
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
Alamofire Xcode 8 Swift 3 results in 786 compile errors
提问by Aaron
I am using the Xcode 8.0 GM. I created a default single-view app with my deployment target set to 9.0.
我正在使用 Xcode 8.0 GM。我创建了一个默认的单视图应用程序,我的部署目标设置为 9.0。
In my Podfile I'm targeting the bleeding edge Swift 3 branch:
在我的 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
I run pod install
and get ... Installing Alamofire (4.0.0-beta.2)
... fantastic, no problems. I open MyProject.xcworkspace
.
我运行pod install
并得到......Installing Alamofire (4.0.0-beta.2)
太棒了,没有问题。我打开MyProject.xcworkspace
。
This pops up:
这弹出:
I can't hit later because it tells me:
我以后不能打,因为它告诉我:
Xcode 8 will not be able to build the target “Alamofire”, and certain editing features will not function properly until the Swift source code in this target has been converted.
Xcode 8 将无法构建目标“Alamofire”,并且在转换此目标中的 Swift 源代码之前,某些编辑功能将无法正常运行。
That's no good, I want to build it. So I hit "Convert". It gives me options:
那不好,我想建造它。所以我点击了“转换”。它给了我选择:
Well that's what I want, Swift 3. Looks good, I hit "next".
嗯,这就是我想要的,Swift 3。看起来不错,我点击了“下一步”。
It defaults to these 3 selected targets. Ok fine, I hit next.
它默认为这 3 个选定的目标。好吧,我打下一个。
What in God's Holy name...
上帝的圣名是什么...
I want to use Alamofire's swift3
bleeding edge branch on an Xcode 8, Swift 3 project targeting iOS 9.0. Where did I go wrong and how can I get this working? FWIW I get a bunch of errors trying to use Alamofire's Swift 2.3 branch so I know it's something I'm doing wrong.
我想在swift3
针对 iOS 9.0 的 Xcode 8、Swift 3 项目上使用 Alamofire 的前沿分支。我哪里出错了,我怎样才能让它工作?FWIW 我在尝试使用 Alamofire 的 Swift 2.3 分支时遇到了一堆错误,所以我知道这是我做错了。
采纳答案by Aaron
Upgrading to the latest Cocoapods (at the time of this answer: version 1.1.0.beta.2
) via the command:
1.1.0.beta.2
通过以下命令升级到最新的 Cocoapods(在此回答时: version ):
gem install cocoapods --pre
seemed to solve the issue for my circumstance.
gem install cocoapods --pre
似乎解决了我的情况的问题。
回答by weskam
I was able to get it working:
我能够让它工作:
update:
更新:
# 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
pod update Alamofire
pod 更新 Alamofire
It should update to 4.0.0-beta.2
There are a few changes when getting a request:
获取请求时有一些变化:
old:
老的:
Alamofire.request(URL_NAME_HERE, withMethod: .get).responseJSON { response in
//Code here.
}
new:
新的:
Alamofire.request(URL_NAME_HERE, method: .get).responseJSON { response in
//Code here.
}
Hope this helps.
希望这可以帮助。
回答by Jonas Zaugg
You should use the master
branch now since the swift3
branch has been merged there. Moreover it's normal for the Xcode Migrator to show that many errors. What it's doing s compiling the code thinking it's a legacy Swift version but since it's already in Swift 3.0, the errors are to be expected. Finally, Xcode is asking you to convert to modern Swift syntax probably because you haven't used the latest version of Cocoapods to install Alamofire.
您master
现在应该使用该分支,因为该swift3
分支已在那里合并。此外,Xcode Migrator 显示许多错误是正常的。它正在做的是编译代码,认为它是一个遗留的 Swift 版本,但由于它已经在 Swift 3.0 中,因此错误是可以预料的。最后,Xcode 要求您转换为现代 Swift 语法,可能是因为您还没有使用最新版本的 Cocoapods 来安装 Alamofire。
NB: event though Cocoapods tells you to use gem install cocoapods --pre
, I prefer using gem update cocoapods --pre
. Else, the older version of Cocoapods stays and still is used when using pod update
. Check what version you're using with pod --version
.
注意:事件虽然 Cocoapods 告诉你使用gem install cocoapods --pre
,但我更喜欢使用gem update cocoapods --pre
. 否则,旧版本的 Cocoapods 在使用pod update
. 检查您正在使用的版本pod --version
。
回答by Rajesh Panda
Update the pod to 1.1.0.rc using the below command.
使用以下命令将 pod 更新到 1.1.0.rc。
sudo gem install cocoapods
sudo gem install cocoapods
use the blow snippet at the end.
最后使用打击片段。
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['SWIFT_VERSION'] = '3.0'
end
end
end
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['SWIFT_VERSION'] = '3.0'
end
end
end
this helps.
这有帮助。
回答by Nour
The solution is to change your request from this
解决方案是从这里更改您的请求
pod 'Alamofire', :git => 'https://github.com/Alamofire/Alamofire.git', :branch => 'swift3'
to this
对此
pod 'Alamofire', :git => 'https://github.com/Alamofire/Alamofire.git', :branch => 'master'
回答by urvashi bhagat
I solved similar issue by using :
我通过使用解决了类似的问题:
platform :ios, '9.0'
use_frameworks!
target 'PROJECT NAME HERE' do
pod 'Alamofire'
end
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['SWIFT_VERSION'] = '3.0'
end
end
end
回答by Nakul Sudhakar
I solved a similar issue by using
我通过使用解决了类似的问题
pod 'Alamofire', '~> 4.0'
in the pod file. I did have to adjust to a higher minimum deployment target.
在 pod 文件中。我确实必须适应更高的最低部署目标。
回答by Zsolt
Not sure if this helps anyone but just in case.. I tried to add Alamofire to a sample quick app on Xcode 8.0 GM using the CocoaPods standalone app.. I kept getting the Convert to swift 2.3 or 3.0 window.. but then I tried from the command line to pod update and it worked. Have no idea why.. I assume the underlying commands for the standalone app are the same.. so not sure what made the difference. In any case after 30 minutes of wasted time mine works.
不确定这是否对任何人有帮助,但以防万一.. 我尝试使用 CocoaPods 独立应用程序将 Alamofire 添加到 Xcode 8.0 GM 上的示例快速应用程序.. 我一直在转换为 swift 2.3 或 3.0 窗口.. 但后来我尝试从命令行到 pod 更新,它工作正常。不知道为什么.. 我假设独立应用程序的底层命令是相同的.. 所以不确定是什么造成的不同。无论如何,在浪费了 30 分钟的时间后,我的工作。
This is the command line screenshot.. same pod file
这是命令行截图..相同的pod文件
回答by Cory Billeaud
I had the same issue, but I uninstalled cocoapods, uninstalled alamofire, then updated my cocoa pods to 1.1.0.beta.2, then used the swift3-rebased branch of Alamofire in my pod file
我遇到了同样的问题,但我卸载了 cocoapods,卸载了 alamofire,然后将我的可可豆更新为 1.1.0.beta.2,然后在我的 pod 文件中使用了 Alamofire 的 swift3-rebased 分支
pod 'Alamofire',
:git => 'https://github.com/Alamofire/Alamofire.git',
:branch => 'swift3-rebased'
pod 'Alamofire',
:git => 'https://github.com/Alamofire/Alamofire.git',
:branch => 'swift3-rebased'
opened my Project.xcworkspace file and all the compiling errors for Alamofire were gone.
打开我的Project.xcworkspace 文件,Alamofire 的所有编译错误都消失了。
回答by Sam
You need to use version 4.0pod 'Alamofire', '~> 4.0'
notice that CocoaPods 1.1 is needed.
您需要使用 4.0 版,pod 'Alamofire', '~> 4.0'
注意需要 CocoaPods 1.1。