Video yükleniyor...
Video Yüklenemedi
I have come across something with the Observation framework that is confusing me so if there are any #SwiftUI Observation framework experts out there that can explain this to me, I would be forever grateful. Why I don’t have to define the object as a State object?
10,171 görüntüleme • 2 yıl önce •via X (Twitter)
8 Yorum

That’s because SwiftUI automatically tracks any observable properties that a view’s body reads directly.

Thanks Maxim. Not sure how I missed that.

The first code's equivalent with the old combine stuff is marking the MyObject as an ObservedObject. This binds it to the lifecycle of the struct, meaning that the property changes retrigger the body, and any re-invocation of the ContentView itself would create a new MyObject. It's due to how the new Observable grabs references of the component that is listening to a certain keypath (\.value in this case) and notifies them of the change.

Expand the macro. This will help in your understanding.

The macro sets state. The protocol expects you to set state

This shows how efficient the macro is compared to ObservableObject, it runs the body but it doesn’t recreate the View

The macro is new. I’m still working on a m1 :(. Older Xcode.

I think the increment operator syntax: += , is colliding -for itself as a variable in the production code below the observable code block, you might need additional syntax for the observable API.
Benzer Videolar
Sensitive content
ØF model Lanah cherry says the only thing that’ll make her quit ØF is if she’s sure that her boyfriend Braeden promises to marry her 🥀 “If he provides for me, if I knew i was getting a family out of this, one hundred percent I would quit, if I don’t get any of that, why would I quit my job and just be left there to be broken up with”
.
21,565 görüntüleme • 3 ay önce
Sensitive content
‘This crazy shit is the reason why don’t go to the gym’ Barbell is mine Pad is mine I don’t have OF There are 10 other racks. So if you don’t come to the gym it’s because you are a lazy MF
StrengthEwa
1,606,437 görüntüleme • 6 ay önce
