Swift 3.1 已經(jīng)正式發(fā)布了,Swift 3.1 是一個(gè)小更新版本,包含對(duì)標(biāo)準(zhǔn)庫(kù)的改進(jìn)。由于 IBM 和社區(qū)其他成員的努力,該版本還包括許多關(guān)于 Swift 的 Linux 實(shí)現(xiàn)的更新。還有一些 Swift 包管理器的更新。
此外,Swift 3.1 編譯器現(xiàn)在可以自動(dòng)預(yù)編譯 Objective-C 橋接頭,還可以加快混合源代碼項(xiàng)目的調(diào)試配置構(gòu)建。
Swift 3.1 與 3.0 兼容,它包含以下的更改和更新,其中大部分都經(jīng)歷了 Swift Evolution process:
新的 Sequence 協(xié)議成員
Sequence
協(xié)議現(xiàn)在有兩個(gè)新成員:
protocol Sequence { // ... /// Returns a subsequence by skipping elements while `predicate` returns /// `true` and returning the remainder. func drop(while predicate: (Self.Iterator.Element) throws -> Bool) rethrows -> Self.SubSequence /// Returns a subsequence containing the initial elements until `predicate` /// returns `false` and skipping the remainder. func prefix(while predicate: (Self.Iterator.Element) throws -> Bool) rethrows -> Self.SubSequence }
點(diǎn)此查看更多:SE-0045: Add prefix(while:)
and drop(while:)
to stdlib
Swift 版本的可用性
Swift 3.1 擴(kuò)展了 @availability
屬性以使用 Swift 版本來(lái)指示聲明的生命周期。例如,在 Swift 3.1 中刪除的 API 將被寫(xiě)為:
@available(swift, obsoleted: 3.1) class Foo { //... }
點(diǎn)此查看更多:SE-0141: Availability by Swift version
Linux 實(shí)現(xiàn)的改進(jìn):
Implementation of NSDecimal
Implementation of NSLengthFormatter
Implementation of Progress
Many improvements to URLSession
functionality, including API coverage and optimized usage of libdispatch
Improved API coverage in NSArray
, NSAttributedString
and many others
Significant performance improvements in Data
. See more details here
Improved JSON serialization performance
Memory leaks fixed in NSUUID
, NSURLComponents
and others
Improved test coverage, especially in URLSession
可編輯的包
默認(rèn)情況下,軟件包的依賴性存儲(chǔ)在工具管理的構(gòu)建目錄中,并且新的 swift package edit
命令允許用戶在軟件包上 “開(kāi)始編輯”,將其移動(dòng)到用戶的控制下(進(jìn)入軟件包目錄),免除依賴更新,允許用戶提交并推送對(duì)該包的更改。
點(diǎn)此查看更多:SE-0082: Package Manager Editable Packages
文章轉(zhuǎn)載自 開(kāi)源中國(guó)社區(qū) [ https://www.oschina.net/news/83314/swift-3-1-released]