<!--
{
  "availability" : [
    "iOS: 17.0.0 -",
    "iPadOS: 17.0.0 -",
    "macCatalyst: -",
    "tvOS: 17.0.0 -",
    "visionOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/UITraitChangeObservable-67e94/registerForTraitChanges(_:action:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "s:5UIKit23UITraitChangeObservableP23registerForTraitChanges_6actionSo0bC12Registration_pSayAA0B10Definition_pXpG_10ObjectiveC8SelectorVtF"
  },
  "title" : "registerForTraitChanges(_:action:)"
}
-->

# registerForTraitChanges(_:action:)

Registers a list of traits to observe, and calls a method on the receiving object when one of the observed traits changes.

```
@discardableResult @MainActor func registerForTraitChanges(_ traits: [UITrait], action: Selector) -> any UITraitChangeRegistration
```

## Parameters

`traits`

An array of traits to observe for changes.

`action`

A selector identifying the method the system calls when one of the registered trait changes.

## Return Value

An opaque token you can use to stop observing trait changes by passing to [`unregisterForTraitChanges(_:)`](/documentation/UIKit/UITraitChangeObservable-67e94/unregisterForTraitChanges(_:)). You don’t have to unregister your observations, and you can safely ignore this value.

## Discussion

This is a convenience method for [`registerForTraitChanges(_:target:action:)`](/documentation/UIKit/UITraitChangeObservable-67e94/registerForTraitChanges(_:target:action:)) when the object receiving the registration is the target of the action. For example, when you register for changes on `self`, the `target` is `self`.

The following example calls [`setNeedsLayout()`](/documentation/UIKit/UIView/setNeedsLayout()) in response to changes to size traits:

```swift
let sizeTraits: [UITrait] = [UITraitVerticalSizeClass.self, UITraitHorizontalSizeClass.self]

// Register for size class changes on self, and invalidate the layout in response to changes.
registerForTraitChanges(sizeTraits, action: #selector(UIView.setNeedsLayout))
```

---

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)