解释 UIView.updateProperties

Asked on 06/12/2025

1 search

UIView.updateProperties is a new method introduced in UIKit to enhance the way views update their properties. It is designed to work alongside the existing layoutSubviews method, providing a more efficient way to update properties without forcing a layout pass. This method is particularly useful for populating content, applying styling, or configuring behaviors.

The updateProperties method runs just before layoutSubviews but is independent of it, allowing you to invalidate properties without triggering a layout pass and vice versa. This separation helps avoid unnecessary work and improves performance by allowing finer-grained updates. It automatically tracks any observable you read, and you can manually trigger it by calling setNeedsUpdateProperties.

For example, if you have an observable model object, changes to this object will automatically trigger updateProperties, allowing the view to update accordingly without needing to rewrite code for unrelated events like resizing.

For more details, you can refer to the session What’s new in UIKit (12:30).

解释 UIView.updateProperties | Ask WWDC