observation observe inside viewModel
Asked on 06/16/2025
2 searches
It seems you're interested in how observation works within a ViewModel, particularly in the context of SwiftUI or UIKit. At WWDC, Apple introduced several enhancements related to observation tracking in both SwiftUI and UIKit.
In the session titled "What’s new in UIKit," automatic observation tracking was discussed. UIKit now supports automatic observation tracking, which allows for dependencies to be automatically established on any observable objects used within a handler. This means that any changes to the model's properties will automatically trigger updates to the UI without requiring extra code. You can learn more about this in the What’s new in UIKit session.
In SwiftUI, observation is also a key feature. The session "Better together: SwiftUI and RealityKit" explains how SwiftUI uses observation to track changes in data and update views accordingly. SwiftUI automatically calls a view's body again when an observable property changes, ensuring that the UI stays in sync with the underlying data. This is particularly useful when working with observable entities in RealityKit, as discussed in the Better together: SwiftUI and RealityKit session.
If you are looking to optimize performance, the session "Optimize SwiftUI performance with Instruments" provides insights into how to manage data dependencies more granularly to ensure that only necessary view bodies are updated when data changes. This can be explored further in the Optimize SwiftUI performance with Instruments session.
These sessions provide a comprehensive overview of how observation is integrated into both UIKit and SwiftUI, allowing for efficient and automatic UI updates in response to data changes.

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.

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.

Optimize SwiftUI performance with Instruments
Discover the new SwiftUI instrument. We’ll cover how SwiftUI updates views, how changes in your app’s data affect those updates, and how the new instrument helps you visualize those causes and effects. To get the most out of this session, we recommend being familiar with writing apps in SwiftUI.