<!--
{
  "documentType" : "article",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/automatic-trait-tracking",
  "metadataVersion" : "0.1.0",
  "role" : "collectionGroup",
  "title" : "Automatic trait tracking"
}
-->

# Automatic trait tracking

Reduce the need to manually register for trait changes when you use traits within a method or closure that supports automatic trait tracking.

## Discussion

Automatic trait tracking is a UIKit feature that eliminates the need to manually register for trait changes when you use traits in a supported method or closure. This feature reduces the amount of code you need to write and maintain, improves performance, and encourages the best practice of using traits within the scope of the supported APIs. For more information, see [Adapting your app when traits change](/documentation/UIKit/adapting-your-app-when-traits-change).

Some properties aren’t appropriate to change during [`layoutSubviews()`](/documentation/UIKit/UIView/layoutSubviews()), for example, properties where setting the value has a side-effect of invalidating the view’s layout. Update these properties in a view’s [`updateProperties()`](/documentation/UIKit/UIView/updateProperties()) method, or a view controller’s [`updateProperties()`](/documentation/UIKit/UIViewController/updateProperties()) method. These methods support automatic trait tracking, and automatic observation tracking on objects that use the <doc://com.apple.documentation/documentation/Observation/Observable()> macro.
Notify an object of other updates to its properties by calling [`setNeedsUpdateProperties()`](/documentation/UIKit/UIView/setNeedsUpdateProperties()) on your view, or [`setNeedsUpdateProperties()`](/documentation/UIKit/UIViewController/setNeedsUpdateProperties()) on your view controller.
Force an object to immediately update its properties by calling [`updatePropertiesIfNeeded()`](/documentation/UIKit/UIView/updatePropertiesIfNeeded()) on your view, or [`updatePropertiesIfNeeded()`](/documentation/UIKit/UIViewController/updatePropertiesIfNeeded()) on your view controller. For more information on automatically observing property updates, see [Updating views automatically with observation tracking in UIKit](/documentation/UIKit/updating-views-automatically-with-observation-tracking-in-uikit).

> Important:
> Avoid causing excessive updates by avoiding changes in ``doc://com.apple.uikit/documentation/UIKit/UIView/layoutSubviews()`` that update properties the object tracks in ``doc://com.apple.uikit/documentation/UIKit/UIView/updateProperties()``, or that invalidate the view’s layout.

A complete list of APIs that support automatic trait tracking appears below.

## Topics

### Views

Views support automatic trait tracking when using traits from the trait collection of the view inside any of the following methods.

[`func updateProperties()`](/documentation/UIKit/UIView/updateProperties())

Configures the view’s content and styling properties before layout.

[`func setNeedsUpdateProperties()`](/documentation/UIKit/UIView/setNeedsUpdateProperties())

Call to manually request a properties update for the view.
Multiple requests may be coalesced into a single update alongside the next layout pass.

[`func updatePropertiesIfNeeded()`](/documentation/UIKit/UIView/updatePropertiesIfNeeded())

Forces an immediate properties update for this view (and its view controller, if applicable)
and any subviews, including any view controllers or views in its subtree.

[`func layoutSubviews()`](/documentation/UIKit/UIView/layoutSubviews())

Lays out subviews.

[`func updateConstraints()`](/documentation/UIKit/UIView/updateConstraints())

Updates constraints for the view.

[`func draw(CGRect)`](/documentation/UIKit/UIView/draw(_:))

Draws the view’s image within the passed-in rectangle.

[`struct Properties`](/documentation/UIKit/UIView/Invalidations/Properties)

### View controllers

View controllers support automatic trait tracking for both the trait collection of the view controller and the trait collection of its view inside any of the following methods.

[`func updateProperties()`](/documentation/UIKit/UIViewController/updateProperties())

Configures the view controller’s content and styling properties.

[`func setNeedsUpdateProperties()`](/documentation/UIKit/UIViewController/setNeedsUpdateProperties())

Call to manually request a properties update for the view controller.
Multiple requests may be coalesced into a single update alongside the next layout pass.

[`func updatePropertiesIfNeeded()`](/documentation/UIKit/UIViewController/updatePropertiesIfNeeded())

Forces an immediate properties update for this view controller and its view,
including any view controllers and views in this subtree.

[`func viewWillLayoutSubviews()`](/documentation/UIKit/UIViewController/viewWillLayoutSubviews())

Notifies the view controller that its view is about to lay out its subviews.

[`func viewDidLayoutSubviews()`](/documentation/UIKit/UIViewController/viewDidLayoutSubviews())

Notifies the view controller when its view finishes laying out its subviews.

[`func updateViewConstraints()`](/documentation/UIKit/UIViewController/updateViewConstraints())

Notifies the view controller when its view needs to update its constraints.

[`func updateContentUnavailableConfiguration(using: UIContentUnavailableConfigurationState)`](/documentation/UIKit/UIViewController/updateContentUnavailableConfiguration(using:))

Updates the content-unavailable configuration for the provided state.

[`- (void) updateContentUnavailableConfigurationUsingState:(UIContentUnavailableConfigurationState *) state;`](/documentation/UIKit/UIViewController/updateContentUnavailableConfigurationUsingState:)

Updates the content-unavailable configuration for the provided state.

### Presentation controllers

Presentation controllers support automatic trait tracking for both the trait collection of the presentation controller and the trait collection of its container view inside any of the following methods.

[`func containerViewWillLayoutSubviews()`](/documentation/UIKit/UIPresentationController/containerViewWillLayoutSubviews())

Notifies the presentation controller that layout is about to begin on the views of the container view.

[`func containerViewDidLayoutSubviews()`](/documentation/UIKit/UIPresentationController/containerViewDidLayoutSubviews())

Notifies the presentation controller when layout ends on the views of the container view.

### Buttons

[`func updateConfiguration()`](/documentation/UIKit/UIButton/updateConfiguration())

Updates the button configuration in response to a button state change.

[`var configurationUpdateHandler: UIButton.ConfigurationUpdateHandler?`](/documentation/UIKit/UIButton/configurationUpdateHandler-swift.property)

A closure that executes when the button state changes.

### Collection view cells

[`func updateConfiguration(using: UICellConfigurationState)`](/documentation/UIKit/UICollectionViewCell/updateConfiguration(using:))

Updates the cell’s configuration using the current state.

[`var configurationUpdateHandler: UICollectionViewCell.ConfigurationUpdateHandler?`](/documentation/UIKit/UICollectionViewCell/configurationUpdateHandler-7rqbu)

A block for handling updates to the cell’s configuration using the current state.

[`- (void) updateConfigurationUsingState:(UICellConfigurationState *) state;`](/documentation/UIKit/UICollectionViewCell/updateConfigurationUsingState:)

Updates the cell’s configuration using the current state.

[`@property (nonatomic, copy, nullable) UICollectionViewCellConfigurationUpdateHandler configurationUpdateHandler;`](/documentation/UIKit/UICollectionViewCell/configurationUpdateHandler-ajhn)

A block for handling updates to the cell’s configuration using the current state.

### Table view cells

[`func updateConfiguration(using: UICellConfigurationState)`](/documentation/UIKit/UITableViewCell/updateConfiguration(using:))

Updates the cell’s configuration using the current state.

[`var configurationUpdateHandler: UITableViewCell.ConfigurationUpdateHandler?`](/documentation/UIKit/UITableViewCell/configurationUpdateHandler-974)

A block for handling updates to the cell’s configuration using the current state.

[`- (void) updateConfigurationUsingState:(UICellConfigurationState *) state;`](/documentation/UIKit/UITableViewCell/updateConfigurationUsingState:)

Updates the cell’s configuration using the current state.

[`@property (nonatomic, copy, nullable) UITableViewCellConfigurationUpdateHandler configurationUpdateHandler;`](/documentation/UIKit/UITableViewCell/configurationUpdateHandler-746ya)

A block for handling updates to the cell’s configuration using the current state.

### Table view headers and footers

[`func updateConfiguration(using: UIViewConfigurationState)`](/documentation/UIKit/UITableViewHeaderFooterView/updateConfiguration(using:))

Updates the view’s configuration using the current state.

[`var configurationUpdateHandler: UITableViewHeaderFooterView.ConfigurationUpdateHandler?`](/documentation/UIKit/UITableViewHeaderFooterView/configurationUpdateHandler-49slo)

A block for handling updates to the view’s configuration using the current state.

[`- (void) updateConfigurationUsingState:(UIViewConfigurationState *) state;`](/documentation/UIKit/UITableViewHeaderFooterView/updateConfigurationUsingState:)

Updates the view’s configuration using the current state.

[`@property (nonatomic, copy, nullable) UITableViewHeaderFooterViewConfigurationUpdateHandler configurationUpdateHandler;`](/documentation/UIKit/UITableViewHeaderFooterView/configurationUpdateHandler-3oji2)

A block for handling updates to the view’s configuration using the current state.

### Collection view compositional layouts

The compositional layout section provider supports automatic trait tracking when using traits from the trait collection of the layout environment in the section provider.

[`typealias UICollectionViewCompositionalLayoutSectionProvider`](/documentation/UIKit/UICollectionViewCompositionalLayoutSectionProvider)

A closure that creates and returns each of the layout’s sections.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)