Customize Consent Preferences

We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.

The cookies that are categorized as "Necessary" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... 

Always Active

Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.

No cookies to display.

Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.

No cookies to display.

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.

No cookies to display.

Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.

No cookies to display.

Advertisement cookies are used to provide visitors with customized advertisements based on the pages you visited previously and to analyze the effectiveness of the ad campaigns.

No cookies to display.

0

苹果发布 Swift 6,强化并发性、测试和跨平台支持,能否摆脱苹果平台局限?

2024年9月22日 – 苹果公司今日发布了 Swift 编程语言的 6.0 版本,与 macOS 15 和 iOS/iPadOS 18 的正式版本同步推出。Swift 6 带来了多项重大改进,包括更安全的并发性、新的标准测试库以及更广泛的跨平台支持,覆盖了 Linux、Windows 和苹果平台。

Swift 作为一种编译语言,以其接近 C 或 C++ 的性能而著称,同时又兼具更安全、更易用的特点。其安全特性包括变量必须在使用前初始化、溢出检查适用于数组和整数、内存管理是自动的,以及默认情况下对象永远不会为 nil(相当于 null)等。

Swift 6 中引入了新的可选模式,通过编译器检查将数据争用错误检测为错误,从而提升了并发编程的安全性和可靠性。数据争用发生在多个线程同时访问同一内存位置时,其结果难以预测。发布公告将这一安全特性描述为“旅程的开始”和“积极开发的领域”。该模式之所以是可选而非默认,主要考虑到误报(假正)的风险,这可能会阻止正常代码的编译,并可能遗漏一些错误。

另一个关键的新特性是引入了名为 Swift Testing 的标准测试框架。这意味着开发人员只需将“import Testing”添加到他们的测试代码中,无需添加进一步的依赖项。

Swift 6 还改进了 C++ 互操作性,通过支持更多 C++ 类型和一众虚拟方法,简化了开发人员将现有代码库迁移到 Swift,并使用 Swift 编写新代码的过程。

其他新特性包括了 128 位整数类型、指定函数抛出的异常类型的能力、对泛型代码中不可复制类型的支持,以及嵌入式 Swift(适用于微控制器等目标)的版本预览。

苹果和开源 Swift 社区都在努力扩大该语言支持的平台数量,现在它的支持范围包括了苹果自己的 Mac 和系列设备平台、Windows 10 及更高版本(x86 和 Arm)、Ubuntu、CentOS 7、Amazon Linux 2、Red Hat 9、Debian 和 Fedora。目前它还不支持取代 Amazon Linux 2 的 Amazon Linux 2023。

由于添加了针对 Linux 的静态 SDK,用 Swift 6 编写 Linux 上的服务端应用程序变得更加容易——例如,开发目标是 Linux 的时候可以在 macOS 或 Windows 上编译代码。使用静态编译还可以消除大多数兼容性问题,但代价是更高的内存使用率和更大的可执行文件。

跨平台的另一个关键特性是,提供核心功能的 Foundation 库现在是用 Swift 编写的,并且在所有平台上都是相同的——这个 2022 年 12 月开始的项目宣告完成。

Swift 能否摆脱其仅限苹果平台的形象?

跨平台支持问题涉及到一个更广泛的问题,即 Swift 是否会完全摆脱其在苹果平台的局限而成为主流。原则上,它具有 Rust 等语言的一些优势——包括原生编译和内存安全——但更容易学习和使用。

到目前为止的证据表明,Swift 的市场依旧是个小圈子。例如,GitHub 存储库的语言统计数据表明,Swift 的使用率实际上有所下降——从 2016年的 1.75% 下降到 2024 年的 1.08%——尽管这绝不是一个全面的使用指标。

推动跨平台支持可能会提高采用率。挑战在于,苹果对 Swift 的投资将一直优先考虑自家平台而非跨平台支持——而且编程社区大多尚未相信该语言的跨平台潜力。

Swift 6 的发布无疑是该语言发展史上的重要里程碑,它为开发者提供了更安全、更强大、更易用的工具。然而,Swift 想要摆脱其仅限苹果平台的形象,还需要克服跨平台支持的挑战,并赢得更多开发者的信任。


>>> Read more <<<

Views: 0

0

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注