swift項目,為適配iOS10,無奈只能更新Xcode 8 ,可是發現一入3.0深似海,從此幸福是路人.於是邊摸索邊修改,在節前的完成代碼遷移.節後在完成手頭工作後,整理思路,把swift3遷移的心得分享大家.
廢話不多說分享下心得:
.app的.(這個是檢測代碼,不然你會哭的)

.app
5>檢測完後.
在左邊的選擇頁中選擇好要轉移的代碼,左邊的代碼是swift3.0代碼,右側代碼時swift2.2代碼->點
Save.

6.png
2、第三方框架篇:(使用的cocoapods管理的第三方框架)
1>發現框架報錯.(不要怕,按照錯誤一樣一樣來)
問題1:--.第三方框架版本問題,"Use Legacy Swift Language Version"
“Use Legacy Swift Language Version” (SWIFT_VERSION) is required to be configured correctly for targets which use Swift. Use the [Edit > Convert > To Current Swift Syntax…] menu to choose a Swift version or use the Build Settings editor to configure the build setting directly.

第三方框架版本問題
在pod的配置文件裡面的Use Legacy Swift Language Version選擇
YES錯誤就消除了
Pods->
TARGETS->指定框架 ->
Build Settings ->
Use Legacy Swift Language Version

pod的配置
問題2:--.lipo:can't open input file:xxx(No such file or directory)

lipo:
PROJRCT->
Build Settings ->
Build Active Architecture only->
YES

lipo
其他問題後續收集再整理...
2>發現框架過時,需要更新框架.
由於3.0的更新,swift各個主流框架都已經及時的推出了新的版本,例如:Alamofire 4.0.0 , SnapKit 3.0.0 , Kingfisher 3.1.0 , SwiftyJSON 也已經更新了專供Swift3的分支.
所以,要更新框架以供使用.

更新主流第三方框架
pod 'SnapKit', '~> 3.0.0'
pod 'SwiftyJSON', :git => 'https://github.com/acegreen/SwiftyJSON.git', :branch => 'swift3'
pod 'Alamofire','~> 4.0.0'
pod 'Kingfisher','~> 3.1.0'
可能會出現以下問題:
SnapKit框架問題:

SnapKit
看到200多個框架錯誤後凌亂了.都是3.0語法了,為什麼還會報錯,不在框架,在自己安裝的cocoapods環境有關系.
解決方案:
需要更新最新環境到cocoapods 1.1.0.rc.2
sudo gem install cocoapods --pre
可以參照SnapKit的官方issues:
https://github.com/SnapKit/SnapKit/issues/300
如果沒有安裝 cocoapods可以參照之前寫的博客.
安裝 cocoapods 1.1.0心得體會:
Alamofire框架問題:

Alamofire
Alamofire/Source/ServerTrustPolicy.swift:243:41: Use of unresolved identifier 'kSecTrustResultInvalid'
Alamofire的官方issues:
https://github.com/Alamofire/Alamofire/issues/1541
解決方案:
上面也提到了,更新最新的Alamofire框架.
pod 'Alamofire','~> 4.0.0'
可能還遇到的問題:
[!] Unable to satisfy the following requirements:
- `Alamofire (~> 4.0.0)` required by `Podfile`
Specs satisfying the `Alamofire (~> 4.0.0)` dependency were found, but they required a higher minimum deployment target.
解決方法:
Alamofire 4.0.0 最低要求系統版本9.0,已經將系統升高到9.0還是無法安裝.
目前的沒有找到有效的解決方法,只有一個方案就是重新立項先集成框架,在把轉接完的代碼遷移到新的項目中去.
10月24日,更新解決方法.
之前提示Alamofire 4.0.0, Podfile報錯.
需要在Podfile文件中指定最低系統9.0項目版本.platform :ios,'9.0'
Alamofire的官方issues:
https://github.com/Alamofire/Alamofire/issues/1639

指定9.0
可能還會有其他框架問題,目前還沒有遇到.歡迎討論.
3.其他問題總結:
關於重建工程來遷移到swift3.0解決方案.
前面也提到了,發現有個別問題無法解決,一直解決也是沒有成效,於是使用目前來說最簡潔的方法就重新建立工程.
先把新建的工程集成好最新支持swift3.0的第三方框架,測試程序可不可以跑通後,再把之前轉換完的代碼一個分類一個分類遷移到新的工程裡面.
至於手工拖入的第三方依賴庫,應用跳轉,按照之前集成好的照搬.或者重新集成.
swift3.0語法的學習.
1.官方已經給出文檔以及轉變說明.
Apple Swift 3.0官方文檔:The Swift Programming Language (Swift 3)

Apple Swift 3.0官方文檔
2.Apple Swift 3.0官方演變:apple/swift-evolution/releases/swift-3_0.md

Swift 3.0官方演變
其主要是廢除了一些API,簡化代碼的書寫,例如取出OC中的NS類前綴,C語言的風格,等等.
3.國外raywenderlich的Swift 3.0遷移介紹:
https://www.raywenderlich.com/135655/whats-new-swift-3

raywenderlich的Swift 3.0
後續持續補充.
後記
對swift3的書寫方式還需要進一步的加強,雖然和之前的寫法有著輕微的改動,使整體變的更加的簡潔、嚴謹,但是稍不注意還是出現莫名其妙的報錯.展望swift4,讓暴風雨來的更猛烈些吧.歡迎討論、批評、指正.