Instance Method

performAsCurrent(_:)

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

Declaration

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

Parameters

actions

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

Discussion

Use this method when you want to execute code using a set of traits that differ from those in the current trait environment. For example, you might use this method to draw part of a view's content with a different set of traits. This method temporarily replaces the traits of the current environment with the ones found in the current 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.