0% found this document useful (0 votes)
8 views1 page

Observed Object

The document describes a wrapper for observable objects that allows for dynamic member lookup and binding to properties via key paths. It explains how to create observed objects with initial values and access their underlying data through the `@ObservedObject` attribute, while also detailing the use of projected values for binding in view hierarchies. Additionally, it introduces the concept of an `OffsetShape`, which allows for translating shapes while retaining their properties.

Uploaded by

jon.moses2000
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views1 page

Observed Object

The document describes a wrapper for observable objects that allows for dynamic member lookup and binding to properties via key paths. It explains how to create observed objects with initial values and access their underlying data through the `@ObservedObject` attribute, while also detailing the use of projected values for binding in view hierarchies. Additionally, it introduces the concept of an `OffsetShape`, which allows for translating shapes while retaining their properties.

Uploaded by

jon.moses2000
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

A wrapper of the underlying observable object that can create bindings to

its properties using dynamic member lookup.


Returns a binding to the resulting value of a given key path.

- Parameter keyPath : A key path to a specific resulting value.

- Returns: A new binding.


Creates an observed object with an initial value.

- Parameter initialValue: An initial value.


Creates an observed object with an initial wrapped value.

You don't call this initializer directly. Instead, declare a property


with the `@ObservedObject` attribute, and provide an initial value.

- Parameter wrappedValue: An initial value.


The underlying value referenced by the observed object.

This property provides primary access to the value's data. However, you
don't access `wrappedValue` directly. Instead, you use the property
variable created with the `@ObservedObject` attribute.

When a mutable value changes, the new value is immediately available.


However, a view displaying the value is updated asynchronously and may
not show the new value immediately.
A projection of the observed object that creates bindings to its
properties using dynamic member lookup.

Use the projected value to pass a binding value down a view hierarchy.
To get the `projectedValue`, prefix the property variable with `$`.
A shape with a translation offset transform applied to it.

An offset shape has two use cases:

1. Used directly via its initializer ``RotatedShape/init(shape:offset:)``.


2. The return value of ``Shape/offset(_:)`` and ``Shape/offset(x:y:)``.

Having an offset shape is helpful because it allows you to translate a shape


and then continue to use its shape properties, instead of turning into ``View``.

A simple example of constructing an ``OffsetShape``:

```
struct OffsetShapeView: View {
var body: some View {
OffsetShape(shape: Circle(),
offset: CGSize(width: 20, height: 20))
}
}
```

![A screenshot displaying a large black circle which is slightly offset


to the right side and lower half of the screen.](20B2CBEC-08BB-4349-B451-
C6DE14BD68A3.png)

You might also like