Protocol¶
DynamicProperty¶
An interface for a stored variable that updates an external property of a view.¶
Declaration¶
protocol DynamicProperty
Overview¶
This protocol is the one that all the data property wrappers implement:
The view gives values to these properties prior to recomputing the view's body.
You will rarely implement this protocol yourself. However, if you do, It would look something like this:
var globalLoadCount = 0
struct CustomProperty: DynamicProperty {
var localLoadCount = 0
mutating func update() {
globalLoadCount += 1
localLoadCount = globalLoadCount
}
}
struct ContentView: View {
@State private var reloadSwitch = false
var customProperty = CustomProperty()
var body: some View {
Text("Load count: \(customProperty.localLoadCount)")
.font(reloadSwitch ? .title : .body)
Button("RELOAD ❗️") { reloadSwitch.toggle() }
}
}

Availability¶
iOS 13.0+
macOS 10.15+
tvOS 13.0+
watchOS 6.0+
Topics¶
Instance Method¶
update() Updates the underlying value of the stored value.
update() Updates the underlying value of the stored value.