mirror of
https://github.com/apple/swift.git
synced 2026-10-28 21:15:56 +01:00
+3








9ead8781d4
Co-authored-by: Alex Martini <amartini@apple.com> Co-authored-by: Graham Lee <glee23@apple.com> Co-authored-by: Chris Adamson <cadamson@apple.com> Co-authored-by: Kirby Turner <kirby_turner@apple.com> Co-authored-by: Paris Pinkney <ppinkney@apple.com> Co-authored-by: Dave Spector <dspector@apple.com> Co-authored-by: Sofia Rodriguez Morales <sofia_rodriguez@apple.com> Co-authored-by: Ethan Kusters <ekusters@apple.com> Co-authored-by: Goli Mohammadi <g_mohammadi@apple.com> Co-authored-by: Adora Vaz <a_vaz@apple.com> Co-authored-by: David Rönnqvist <ronnqvist@apple.com> Co-authored-by: Nate Merseth Cook <natecook@apple.com> Co-authored-by: Susan Conant <susan_c@apple.com>
936 B
936 B
Observation/withObservationTracking(_:onChange:)
@Metadata { @DocumentationExtension(mergeBehavior: override) }
Tracks access to properties.
This method tracks access to any property within the apply closure, and
informs the caller of value changes made to participating properties by way of
the onChange closure. For example, the following code tracks changes to the
name of cars, but it doesn't track changes to any other property of Car:
func render() {
withObservationTracking {
for car in cars {
print(car.name)
}
} onChange: {
print("Schedule renderer.")
}
}
-
Parameters:
- apply: A closure that contains properties to track.
- onChange: The closure invoked when the value of a property changes.
-
Returns: The value that the
applyclosure returns if it has a return value; otherwise, there is no return value.