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

Returns a view that reads the value of preference Key from self, uses that to produce another view which is displayed as as the background to self.

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

Returns a view that reads the value of preference Key from self, uses that to produce another view which is displayed as an overlay on self.