Swift 4.2 正式釋出:泛型改進,更快更相容!
Swift 4.2 現已正式釋出!Swift 4.2 基於 Swift 4 的優勢,提供更快的編譯時間,改進除錯體驗,更新標準庫以及融合二進位制相容性。
泛型改進
隨著對 conditional conformance 的支援,Swift 4.2 在泛型方面取得了重大進展,像是減少樣板程式碼的數量,使更多程式碼可重用等等。要了解有關 conditional conformance 的更多資訊,請參閱:
標準庫更新
Swift 4.2 中的標準庫包含許多新特性,比如 Hashable 協議的改進以及新的統一隨機化函式(randomization functions)和協議集。
二進位制相容性
Swift 4.2 使語言更接近穩定的 ABI ,為未來的 Swift 版本實現二進位制相容性。訪問 ABI Dashboard 可 瞭解有關此項工作當前進展的更多詳情。
其他語言和編譯器更新
Swift 4.2 包含許多對開發者體驗有顯著影響的改進,包括:
-
Support for batch mode compilation resulting in faster build times
-
Change in calling convention for retain/release cycle to reduce code size and improve runtime performance
-
Lazier SIL deserialization with -Onone
-
Recursive metadata support
-
More compact reflection metadata
-
Default arguments are inlined at call sites
-
Some long-standing bug fixes, including init declname, switch with multiple case labels per block, inheritance of generic initializers, and more
Swift 4.2 還實現了 Swift Evolution 上的一些提案:
-
SE-0054 Abolish ImplicitlyUnwrappedOptional type . Read even more details about the reimplementation here .
-
SE-0079 Allow using optional binding to upgrade self from a weak to strong reference
-
SE-0195 Introduce User-defined “Dynamic Member Lookup” Types
-
SE-0205 withUnsafePointer(to:_:) and withUnsafeBytes(of:_:) for immutable values
包管理器更新
Swift 4.2 為 Swift 包管理器引入了新功能:
-
支援批處理模式 .Swift targets will be now compiled using the Swift compiler’s batch mode.
-
Improved scheme generation logic.The scheme generation logic is improved and generates schemes as follows:
-
One scheme containing all regular and test targets of the root package.
-
One scheme per executable target containing the test targets whose dependencies intersect with the dependencies of the executable target.
-
Automatic Xcode project generation.The generate-xcodeproj has a new –watch option to watch the file system and automatically regenerate the Xcode project if needed. This uses the watchman tool to watch the required files.
Swift 4.2 還實現了 Swift Evolution 上關於包管理器的一些提案:
-
SE-0201 Package Manager Local Dependencies . SwiftPM now supports declaring dependency on a package using its path on disk instead of the git URL. This requires updating the package’s tools version to 4.2.
-
SE-0208 Package Manager System Library Targets . The PackageDescription API in tools version 4.2 supports a new type of target “system library target”, which moves the current system-module packages feature from package to target level.
-
SE-0209 Package Manager Swift Language Version API Update .
swiftLanguageVersions
property in PackageDescription manifest API for tools version 4.2 is changed from an array of Integers to an array of SwiftVersion enum.
遷移說明和更新細節可查閱:
下載地址: