在 UIKit 中响应 Observation 的功能,是否有做向后兼容?
Asked on 06/15/2025
1 search
在 WWDC 2025 的 "What’s new in UIKit" 会议中,Apple 介绍了在 UIKit 中对 Swift 可观察对象的内置支持。UIKit 现在在更新方法中集成了 Swift 的观察功能,例如 layoutSubviews
。这意味着 UIKit 可以自动跟踪任何可观察的视图引用,连接依赖关系,并在需要时使视图失效。
对于向后兼容性,您可以在 iOS 18 上通过在 info.plist
中添加 UIObservationTrackingEnabled
键来启用此功能。在 iOS 26 中,这个功能是默认启用的。这意味着即使在较旧的 iOS 版本上,您也可以利用这个新功能,只需进行一些配置。
如果您想了解更多关于自动观察跟踪的内容,可以查看 What’s new in UIKit (10:21) 章节。

What’s new in UIKit
Modernize your app with the latest APIs in UIKit, including enhanced menu bar support, automatic observation tracking, a new UI update method, and improvements to animations. We’ll also cover how you can include SwiftUI scenes in your UIKit app and explore SF Symbols, HDR color pickers, and more.

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.

Better together: SwiftUI and RealityKit
Discover how to seamlessly blend SwiftUI and RealityKit in visionOS 26. We’ll explore enhancements to Model3D, including animation and ConfigurationCatalog support, and demonstrate smooth transitions to RealityView. You’ll learn how to leverage SwiftUI animations to drive RealityKit component changes, implement interactive manipulation, use new SwiftUI components for richer interactions, and observe RealityKit changes from your SwiftUI code. We’ll also cover how to use unified coordinate conversion for cross-framework coordinate transformations.