Generic Instance Method

onPreferenceChange(_:perform:)

Adds an action to perform when the specified preference key’s value changes.

Declaration

func onPreferenceChange<K>(_ key: K.Type = K.self, perform action: @escaping (K.Value) -> Void) -> some View where K : PreferenceKey, K.Value : Equatable

Parameters

key

The key to monitor for value changes.

action

The action to perform when the value for key changes. The action closure passes the new value as its parameter.

Return Value

A view that triggers action when the value for key changes.

See Also

Responding to View Preferences

func backgroundPreferenceValue<Key, T>(Key.Type, (Key.Value) -> T) -> View

Uses the specified preference value from the view to produce another view as a background to the first view.

func overlayPreferenceValue<Key, T>(Key.Type, (Key.Value) -> T) -> View

Uses the specified preference value from the view to produce another view as an overlay atop the first view.