<!--
{
  "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/performAsCurrent(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(cs)UITraitCollection(im)performAsCurrentTraitCollection:"
  },
  "title" : "performAsCurrent(_:)"
}
-->

# performAsCurrent(_:)

Executes custom code using the traits of the receiving trait collection.

```
func performAsCurrent(_ actions: () -> Void)
```

## Parameters

`actions`

A closure containing the code you want to execute. This closure has no return value and takes no parameters.

## Discussion

The [`current`](/documentation/UIKit/UITraitCollection/current) property is undefined outside the documented methods where UIKit sets it. Use this method when you want to execute code that relies on the [`current`](/documentation/UIKit/UITraitCollection/current) property from outside these methods. You can also use this method if you want to execute some code using the traits of a different trait environment. Prefer this method over manually setting the [`current`](/documentation/UIKit/UITraitCollection/current) property yourself.

This method temporarily replaces the traits of the current environment with the ones in the targeted [`UITraitCollection`](/documentation/UIKit/UITraitCollection). After the `actions` block finishes, the method restores the original traits to the environment. You can call this method from any thread of your app.

The example below shows how you can safely resolve dynamic [`UIColor`](/documentation/UIKit/UIColor) that relies on [`current`](/documentation/UIKit/UITraitCollection/current):

```swift
func updateBorderColor(layer: CALayer) {
    
    // Read the trait collection from the view.
    let traitCollection = view.traitCollection
    traitCollection.performAsCurrent {
        // Inside the closure, the current property is set to traitCollection,
        // which UIColor uses to resolve the dynamic color borderColor.
        layer.borderColor = UIColor.label.cgColor
    }
}
```

---

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)