Swift微信公众号: SwiftMic
Swift 5.4 新特性
Swift 5.4
已于 4 月 26 日正式发布,本次更新带来了一些新特性,整理如下:
-
Support for multiple variadic parameters in functions, subscripts and initializers (SE-0284)
-
Extend implicit member syntax (SE-0287)
-
Result builders (SE-0289)
-
Local functions supporting overloading
-
Property wrappers for local variables
另外,Async/await
特性将在 Swift 5.5
中实现,编译器将对目前使用 await
作为标识符的地方会触发一个提醒,以便为未来的 Async/await
特性铺路。
关于
Swift 5.4
以及未来Swift
版本的新特性,详情可见Swift Evolution
优化 Runtime 性能以及 Code 大小
在 Swift 5.4
中得益于更快的 hash 表算法的实现,运行时的 protocol 一致性(protocol conformance)检查速度将显著提高。这也提高了 as?
和 as!
操作的性能。
另外,针对如下情况也做了优化,以避免重复检查:
func foo(_ a: inout [Int]) {
// Must do copy-on-write (CoW) check here.
a[0] = 1
// The compiler no longer generates
// a redundant CoW check here.
a[1] = 2
}
还有一些其他优化整理如下:
-
String
interpolations are more aggressively constant-folded - Fewer retain/release calls, especially for inout function arguments and within loops
- Generic metadata in the Standard Library is now specialized at compile time, reducing dirty memory usage and improving performance
Swift Package Manager 更新
Swift 5.4
中 Swift Package Manager
有一些重要更新,如下:
- Swift packages that specify a 5.4 tools version can now explicitly declare targets as executable, which allows the use of the
@main
keyword in package code (SE-0294) - Swift Package Manager is now supported on Windows!
- Swift Package Manager caches package dependencies on a per-user basis, which reduces the amount of network traffic and increases performance of dependency resolution for subsequent uses of the same package
- Automatic test discovery is now the default on all platforms, removing the need in
LinuxMain.swift
(which has been deprecated) - Multiple improvements to dependencies resolution infrastructure including in manifest loading and caching, leading to improved performance of dependency resolution
- Improved diagnostics infrastructure and error messages, leading to more actionable error messages for dependency resolutions issues and beyond
在作者看来,最大的更新应该就是 Swift Package Manager
支持 Windows
平台了。
Windows 平台
除了 Swift Package Manager
支持 Windows
平台外,Swift
在 Windows
平台上也有一些其它更新,如下:
- The
WinSDK
module has been extended, covering a greater portion of the Windows developer SDK. This allows more of the APIs to be easily used for Windows applications without having to manually construct libraries to bridge the C interfaces to Swift - Improvements to the installer should make using the toolchain with external tools easier by reducing the flags needed by default on Windows
参考
关于 Swift 5.4
版本的详细介绍可阅读 Swift
官方 Blog :
网友评论