升级Xcode8.1 遇到的更新swift3.0的问题

来源:互联网 发布:jquery怎么定义数组 编辑:程序博客网 时间:2024/04/24 06:19

前言:

Swift项目,为适配iOS10,无奈只能更新Xcode 8 ,可是发现一入3.0深似海,从此幸福是路人.于是边摸索边修改,在节前的完成代码迁移.节后在完成手头工作后,整理思路,把swift3迁移的心得分享大家.
废话不多说分享下心得:

1、代码篇:(一定要做好备份!!!)


1>升级Xcode8正式版(8A218a).


Xcode 8 

2>使用系统自带的桥接工具.(原装的就是好,直接打开2.2项目也会提醒->步骤:3)

Edit > Convert > To Current Swift Syntax..

桥接选项

3>不用说就是为3.0来的,选择Swift3.


Swift3.0

4>上面的框架就不用选了,只选择.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的分支.
所以,要更新框架以供使用.


更新主流第三方框架
<code class="php">pod <span class="hljs-string" style="color: rgb(0, 136, 0);">'SnapKit'</span>, <span class="hljs-string" style="color: rgb(0, 136, 0);">'~> 3.0.0'</span>pod <span class="hljs-string" style="color: rgb(0, 136, 0);">'SwiftyJSON'</span>, :git => <span class="hljs-string" style="color: rgb(0, 136, 0);">'https://github.com/acegreen/SwiftyJSON.git'</span>, :branch => <span class="hljs-string" style="color: rgb(0, 136, 0);">'swift3'</span>pod <span class="hljs-string" style="color: rgb(0, 136, 0);">'Alamofire'</span>,<span class="hljs-string" style="color: rgb(0, 136, 0);">'~> 4.0.0'</span>pod <span class="hljs-string" style="color: rgb(0, 136, 0);">'Kingfisher'</span>,<span class="hljs-string" style="color: rgb(0, 136, 0);">'~> 3.1.0'</span></code>

可能会出现以下问题:

  • SnapKit框架问题:

SnapKit

看到200多个框架错误后凌乱了.都是3.0语法了,为什么还会报错,不在框架,在自己安装的cocoapods环境有关系.

解决方案:
需要更新最新环境到cocoapods 1.1.0.rc.2

<code class="sql">sudo gem <span class="hljs-operator"><span class="hljs-keyword" style="color: rgb(0, 0, 136);">install</span> cocoapods <span class="hljs-comment" style="color: rgb(136, 0, 0);">--pre</span></span></code>

可以参照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框架.

<code class="bash">pod <span class="hljs-string" style="color: rgb(0, 136, 0);">'Alamofire'</span>,<span class="hljs-string" style="color: rgb(0, 136, 0);">'~> 4.0.0'</span></code>

可能还遇到的问题:

<code class="scheme">[<span class="hljs-keyword" style="color: rgb(0, 0, 136);">!</span>] Unable to satisfy the following requirements:- `Alamofire <span class="hljs-list">(<span class="hljs-keyword" style="color: rgb(0, 0, 136);">~></span> <span class="hljs-number" style="color: rgb(0, 102, 102);">4.0</span>.0)</span>` required by `Podfile`Specs satisfying the `Alamofire <span class="hljs-list">(<span class="hljs-keyword" style="color: rgb(0, 0, 136);">~></span> <span class="hljs-number" style="color: rgb(0, 102, 102);">4.0</span>.0)</span>` dependency were found, but they required a higher minimum deployment target.</code>


需要在Podfile文件中指定最低系统9.0项目版本.platform :iOS,'9.0'
Alamofire的官方issues:
https://github.com/Alamofire/Alamofire/issues/1639


指定9.0
0 0
原创粉丝点击