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) -> Self.Modified<_PreferenceActionModifier<K>> 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) -> _DelayedPreferenceView<Key, Self.Modified<_BackgroundModifier<_PreferenceReadingView<Key, T>>>>

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

Beta
func overlayPreferenceValue<Key, T>(Key.Type, (Key.Value) -> T) -> _DelayedPreferenceView<Key, Self.Modified<_OverlayModifier<_PreferenceReadingView<Key, T>>>>

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

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