<!--
{
  "availability" : [
    "iOS: 17.0.0 -",
    "iPadOS: 17.0.0 -",
    "macCatalyst: 17.0.0 -",
    "tvOS: 17.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/UITraitChangeObservable-7qoet/registerForTraitChanges:withAction:",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(pl)UITraitChangeObservable(im)registerForTraitChanges:withAction:"
  },
  "title" : "registerForTraitChanges:withAction:"
}
-->

# registerForTraitChanges:withAction:

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

```
- (id<UITraitChangeRegistration>) registerForTraitChanges:(NSArray<Class<UITraitDefinition>> *) traits withAction:(SEL) action;
```

## 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)