今年 Notification 有改动吗?比如 Sendable
Asked on 06/19/2025
1 search
在WWDC 2025的“What's new in Swift”会议中,关于通知的处理有一些改动。具体来说,通知名称和负载现在支持具体类型(concrete types),这使得编译器可以检查对象是否支持你注册的通知类型。这种改动减少了处理通知负载时的样板代码,并且通知类型还指定了通知发布的位置。对于在主线程上发布的通知,符合mainactor消息的通知保证总是同步发布在主线程上。对于异步消息,通知会在任意线程上异步发布。这些具体的通知类型在UIKit和Foundation等框架中可用,你也可以为自己的通知添加具体类型。
关于Sendable,虽然在“What's new in Swift”会议中没有直接提到Sendable与通知的关系,但在“迁移到Swift 6”会议中提到了一些关于Sendable的内容。具体来说,标记类型为Sendable可以帮助解决数据竞争问题。
如果你对这些改动的具体细节感兴趣,可以查看What's new in Swift (10:45)的相关章节。

What’s new in Swift
Join us for an update on Swift. We’ll talk about workflow improvements that make you more productive, and new and modernized library APIs for fundamental programming tasks. We’ll show examples of Swift adoption throughout more layers of the software stack. Finally, we’ll explore new language features for both improving approachability of concurrency, and achieving peak performance when you need it.

Explore App Store server APIs for In-App Purchase
Learn how to leverage your server to build great In-App Purchase experiences with the latest updates to the App Store Server API, App Store Server Notifications, and the open source App Store Server Library. After a recap of current APIs, we’ll introduce updated endpoint functionality, new transaction fields, and a new notification type. We’ll also discuss best practices for the purchase lifecycle, delivering content, and targeting offers, so you can become a server power user.

Learn more about Declarative Web Push
Learn how Declarative Web Push can help you deliver notifications more reliably. Find out how to build on existing standards to be more efficient and transparent by design while retaining backwards compatibility with original Web Push.