<!--
{
  "availability" : [
    "iOS: 13.0.0 -",
    "iPadOS: 13.0.0 -",
    "macCatalyst: 13.1.0 -",
    "tvOS: 13.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/UITraitCollection/current",
  "metadataVersion" : "0.1.0",
  "role" : "Type Property",
  "symbol" : {
    "kind" : "Type Property",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(cs)UITraitCollection(cpy)currentTraitCollection"
  },
  "title" : "current"
}
-->

# current

The trait collection for the current execution context.

```
class var current: UITraitCollection { get set }
```

## Discussion

This property provides a way to get a trait collection from the currently updating trait environment when your code doesn’t have direct access to the trait environment. UIKit updates the value of this property before calling the following methods of [`UIView`](/documentation/UIKit/UIView), [`UIViewController`](/documentation/UIKit/UIViewController), and [`UIPresentationController`](/documentation/UIKit/UIPresentationController). Inside these methods, the trait collection contains the traits describing the currently updating view or controller.

The following table lists the supported methods where UIKit sets the [`current`](/documentation/UIKit/UITraitCollection/current) value:

|``doc://com.apple.uikit/documentation/UIKit/UIView``                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |``doc://com.apple.uikit/documentation/UIKit/UIViewController``                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |``doc://com.apple.uikit/documentation/UIKit/UIPresentationController``                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|``doc://com.apple.uikit/documentation/UIKit/UIView/draw(_:)`` ![](spacer) ``doc://com.apple.uikit/documentation/UIKit/UIView/layoutSubviews()`` ![](spacer) ``doc://com.apple.uikit/documentation/UIKit/UIView/tintColorDidChange()`` ![](spacer) The `action` method of ``doc://com.apple.uikit/documentation/UIKit/UITraitChangeObservable-67e94/registerForTraitChanges(_:target:action:)`` ![](spacer) The `handler` closure of ``doc://com.apple.uikit/documentation/UIKit/UITraitChangeObservable-67e94/registerForTraitChanges(_:handler:)``  ![](spacer) ``doc://com.apple.uikit/documentation/UIKit/UITraitEnvironment/traitCollectionDidChange(_:)``|``doc://com.apple.uikit/documentation/UIKit/UIViewController/viewWillLayoutSubviews()``  ![](spacer) ``doc://com.apple.uikit/documentation/UIKit/UIViewController/viewDidLayoutSubviews()`` ![](spacer) The `action` method of ``doc://com.apple.uikit/documentation/UIKit/UITraitChangeObservable-67e94/registerForTraitChanges(_:target:action:)`` ![](spacer) The `handler` closure of ``doc://com.apple.uikit/documentation/UIKit/UITraitChangeObservable-67e94/registerForTraitChanges(_:handler:)``  ![](spacer) ``doc://com.apple.uikit/documentation/UIKit/UITraitEnvironment/traitCollectionDidChange(_:)``|``doc://com.apple.uikit/documentation/UIKit/UIPresentationController/containerViewWillLayoutSubviews()`` ![](spacer) ``doc://com.apple.uikit/documentation/UIKit/UIPresentationController/containerViewDidLayoutSubviews()`` ![](spacer) The `action` method of ``doc://com.apple.uikit/documentation/UIKit/UITraitChangeObservable-67e94/registerForTraitChanges(_:target:action:)`` ![](spacer) The `handler` closure of ``doc://com.apple.uikit/documentation/UIKit/UITraitChangeObservable-67e94/registerForTraitChanges(_:handler:)`` ![](spacer) ``doc://com.apple.uikit/documentation/UIKit/UITraitEnvironment/traitCollectionDidChange(_:)``|

Outside these methods, you’re responsible for ensuring the [`current`](/documentation/UIKit/UITraitCollection/current) property has a valid trait collection. Otherwise, the contents of the collection are undefined. To ensure that [`current`](/documentation/UIKit/UITraitCollection/current) contains a valid trait collection, use one of these techniques:

- Use [`performAsCurrent(_:)`](/documentation/UIKit/UITraitCollection/performAsCurrent(_:)) to execute your code inside a context with a valid [`current`](/documentation/UIKit/UITraitCollection/current) property. This is the preferred way to set [`current`](/documentation/UIKit/UITraitCollection/current).
- Set [`current`](/documentation/UIKit/UITraitCollection/current) to a known good trait collection. If you set [`current`](/documentation/UIKit/UITraitCollection/current), you need to save and restore the trait environment, as the code example below shows.

[`UIColor`](/documentation/UIKit/UIColor) implicitly uses the [`current`](/documentation/UIKit/UITraitCollection/current) trait collection when it resolves a dynamic color to a static color value, such as a <doc://com.apple.documentation/documentation/CoreGraphics/CGColor> or an RGB value. To resolve a dynamic color, make sure that [`current`](/documentation/UIKit/UITraitCollection/current) contains a valid collection. Alternatively, the method [`resolvedColor(with:)`](/documentation/UIKit/UIColor/resolvedColor(with:)) resolves a color from a given trait collection and doesn’t rely on [`current`](/documentation/UIKit/UITraitCollection/current).

UIKit stores the value of the [`current`](/documentation/UIKit/UITraitCollection/current) property as a thread-local variable, so access is lightweight and free of side effects. Changing the traits on a nonmain thread doesn’t affect the current traits on your app’s main thread.

Whenever possible, use [`performAsCurrent(_:)`](/documentation/UIKit/UITraitCollection/performAsCurrent(_:)) rather than manually setting [`current`](/documentation/UIKit/UITraitCollection/current). If you need to set [`current`](/documentation/UIKit/UITraitCollection/current), keep the following in mind:

- Before modifying [`current`](/documentation/UIKit/UITraitCollection/current), save the value, and restore it after you’re done.
- Always start with a trait collection from a concrete instance of [`UITraitEnvironment`](/documentation/UIKit/UITraitEnvironment) rather than creating a new [`UITraitCollection`](/documentation/UIKit/UITraitCollection) instance.

The [`performAsCurrent(_:)`](/documentation/UIKit/UITraitCollection/performAsCurrent(_:)) method handles these tasks for you.

The example below sets the [`current`](/documentation/UIKit/UITraitCollection/current) property to resolve a dynamic color into a <doc://com.apple.documentation/documentation/CoreGraphics/CGColor>:

```swift
func updateBorderColor(layer: CALayer) {
    let savedTraitCollection = UITraitCollection.current
    // Set the property with a trait collection from a view.
    UITraitCollection.current = view.traitCollection
    // Methods and properties relying on current are safe to use here.
    layer.borderColor = UIColor.label.cgColor
    // Restore the saved collection.
    UITraitCollection.current = savedTraitCollection
}
```

---

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)