The beta version of Swift 3 is now out of the box, and Chris Lattner in the mail before saying that Swift 3 was almost completely completed in August.
One of the biggest problems in writing a demo or a project migrating to Swift 3.0 should be the addition of a third-party library
The swift community has always been full of enthusiasm, such as Alamofire, decodable and other Third-party libraries have branches of Swift 3.0, but if not handled at the time of import, there will always be a variety of problems, I am here to share my own solution
In fact, there are only two main issues to deal with.
Specify a specific branch of a Third-party library
Specify the version of Swift compiled within the project file
Cocoapods
Here take Alamofire as an example, the main thing is to add something to the podfile.
Specify a branch
The first is to specify the branch, cocoapods itself only supports the name and version two parameters, but we can specify the Git warehouse, and then specify Branch, in the following format:
Pod ' Alamofire ',: Git => ' https://github.com/Alamofire/Alamofire.git ',: Branch => ' swift3 '
Specifying a compiled version
There is also the release of the specified Swift, as long as the following sentences are added at the end of the project, where a few words iterate over target in the project, modifying all Target's Swift compiled version
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
But there is a drawback, objective-c and Swift's mixed project, if you want to introduce the OC library, you can not do so, but one to set the compiled version is too cumbersome, I think the simplest or directly into the project, the swift_version to delete the item It's okay.
Complete Podfile as follows:
Project ' Sample.xcodeproj '
Platform:ios, ' 9.0 '
Target ' sample ' do
use_frameworks!
Pod ' Alamofire ',: Git => ' https://github.com/Alamofire/Alamofire.git ',: Branch => ' swift3 '
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
Carthage
Carthage of the specific use I do not explain, in fact, I personally still prefer Carthage, their own operation over again basically can understand the process of Third-party library import
Specify a branch
Carthage because it is a centralized package manager, so select a branch within the Cartfile
GitHub "Alamofire/alamofire" "swift3"
Specifying a compiled version
Carthage Compilation is very simple, swift 3 words directly Carthage Update on the line, Xcodebuild point to Xcode 8 under the premise of the default Swift 3, but Swift 2.3 will need to specify the version, as follows:
Toolchains=com.apple.dt.toolchain.swift_2_3 Carthage Update--platform iOS
And then there's one thing to be aware of when compiling is that Carthage will call Xcode build to mutate by default, and if we have two versions of Xcode at the same time, we need to make sure that the Xcode builds.
If it's not Xcode 8, just run the order to change it.
sudo./xcode-select-switch/applications/xcode-beta.app/