Automatic observation tracking
Simplify updating views when data changes by making updates in methods that support automatic observation tracking.
Overview
Use automatic observation tracking to update your views in response to model object changes without manually invalidating views. Mark your model classes with the Observable macro, then read model properties in methods like updateProperties() or layoutSubviews(). UIKit tracks which properties you access and automatically calls these methods again when those properties change. This approach eliminates the need to manually call methods like setNeedsLayout() or setNeedsDisplay() after updating model data, reducing opportunities for bugs and outdated displays.
These methods support automatic observation tracking in views, view controllers, presentation controllers, buttons, collection view cells, table view cells, and table view headers and footers. For more information, see Updating views automatically with observation tracking.
Topics
Observing data in views
Observing data in view controllers
updateProperties()viewWillLayoutSubviews()viewDidLayoutSubviews()updateViewConstraints()updateContentUnavailableConfiguration(using:)