Adds an action to perform when the specified preference key’s value changes.
SDKs
- iOS 13.0+
- macOS 10.15+
- Mac Catalyst 13.0+
- tvOS 13.0+
- watchOS 6.0+
- Xcode 11.0+
Framework
- Swift
UI
Declaration
func onPreferenceChange<K>(_ key: K.Type = K.self, perform action: @escaping (K.Value) -> Void) -> some View where K : Preference Key, K.Value : Equatable
Parameters
key
The key to monitor for value changes.
action
The action to perform when the value for
key
changes. Theaction
closure passes the new value as its parameter.
Return Value
A view that triggers action
when the value for key
changes.