mirror of
https://github.com/apple/swift.git
synced 2026-09-30 10:17:34 +02: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>
24 lines
634 B
Markdown
24 lines
634 B
Markdown
# ``Observation/Observable()``
|
|
|
|
@Metadata {
|
|
@DocumentationExtension(mergeBehavior: override)
|
|
}
|
|
|
|
Defines and implements conformance of the Observable protocol.
|
|
|
|
This macro adds observation support to a custom type and conforms the type
|
|
to the ``Observation/Observable`` protocol. For example, the
|
|
following code applies the `Observable` macro to the type `Car` making it
|
|
observable:
|
|
|
|
@Observable
|
|
class Car {
|
|
var name: String = ""
|
|
var needsRepairs: Bool = false
|
|
|
|
init(name: String, needsRepairs: Bool = false) {
|
|
self.name = name
|
|
self.needsRepairs = needsRepairs
|
|
}
|
|
}
|