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.

Beta
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.

Beta

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software