SwiftUI by example: @ObservedObject vs. @StateObject. Why Apple had to add a new property wrapper?

  Рет қаралды 8,431

Karin Prater

Karin Prater

Күн бұрын

Пікірлер: 26
@alex-gz7ud
@alex-gz7ud 2 жыл бұрын
I wish I can give you 100 likes... Awesome explanation with example!!
@asseeger
@asseeger 3 жыл бұрын
Very valuable inputs, thanks! It kind of clicked now for me what happens when a binding property is recreated because a view is recreated. Well done.
@benceylan273
@benceylan273 3 жыл бұрын
Thanks. I like your teaching style. Using Dark mode Xcode on your tutorials would be better.
@borkware
@borkware 3 жыл бұрын
as someone who finds darkmode difficult to read, I respectfully disagree :-)
@SwiftyPlace
@SwiftyPlace 3 жыл бұрын
Just when I thought I should give dark mode a try 😂
@borkware
@borkware 3 жыл бұрын
@@SwiftyPlace You do you. It's your channel :-D
@UMBerto-wj7ch
@UMBerto-wj7ch 3 жыл бұрын
+1 for dark mode. Definitely.
@XBassSlayerX
@XBassSlayerX 3 жыл бұрын
Some of the best SwiftUI content on KZbin. 10/10
@byaruhaf
@byaruhaf 2 жыл бұрын
Thanks Karin, Awesome Explanation.
@vladimirmoor
@vladimirmoor 3 жыл бұрын
Thanks! Very helpful video! Perfect explaining differences where use @StateObject and where @ObservedObject.
@valentine1925
@valentine1925 3 жыл бұрын
this is superb!! you like made a shortcut for the gotchas of those property wrappers
@antonsergeyev2624
@antonsergeyev2624 3 жыл бұрын
Thanks for the great Video!
@_walkman
@_walkman 3 жыл бұрын
Thank you. Exactly what I was looking for :-)
@zzzMrAngelzzz
@zzzMrAngelzzz 3 жыл бұрын
Thank you! Your doing a great content!
@dannestrom
@dannestrom 3 жыл бұрын
Wouldn't it also be possible to wrap the Player in a struct and use @State with that struct? The struct will be preserved when the view is re-created, and the struct will instantiate the Player in it's constructor, so the Player object will also be preserved between view re-creations.
@lichb0rn
@lichb0rn 3 жыл бұрын
And then you'll end up with a lot of environment objects :) Maybe it's my little coding experience, but I feel in pursue to solve some problems of UIKitI, Apple made others with passing data in SwiftUI.
@kell7689
@kell7689 3 жыл бұрын
I like your explanations! Are you optimistic about SwiftUI for the long term?
@SwiftyPlace
@SwiftyPlace 3 жыл бұрын
I have some mixed feelings about it. SwiftUI gets more stable (that means I don't have to check the app functionality with every new iOS release). The crucial point for me is NavigationView. It keeps on pushing some of my views in an "unexpected behaviour". As long as I don't have very specific design requirements, SwiftUI is great and fast. But customisation sometimes takes me more time than just UIKit would have taken me. Take MapView for example. For more control (which is most cases), I would need to drop down to UIKit. For me the new features and evolution of SwiftUI are not moving very fast. During WWDC2021 we got mostly design features e.g. button styles but nothing ground breaking.
@kell7689
@kell7689 3 жыл бұрын
@@SwiftyPlace I feel the same, and I also have issues with how Navigation is handled. I hope SwiftUI becomes everything I hope it will. Coming to this from the Android SDK is like a dream, just need it to fill out a bit more.
@markaurelius61
@markaurelius61 2 жыл бұрын
At 7:30 Herr Katze is very interested in the fact that @Published properties have a Publisher.
@littlerubiesdaycare
@littlerubiesdaycare 3 жыл бұрын
Thanks for sharing this. I did a little bit of physics and chemistry in highschool and quickly realized it wasn't for me. I do however derive satisfaction from watching people who know physics. Hope you check us out too
@ahmedalfrash9300
@ahmedalfrash9300 3 жыл бұрын
thank you
@victorriurean
@victorriurean Жыл бұрын
cool
@denages
@denages 2 жыл бұрын
The example is too obvious. Everyone uses too simple cases. Show something like passing a ViewModel to a cell view as a parameter (the view model also has its parameters) where the cell view should react on different view models passed in. What kind of state will you use? If you use @ObservableObject then you can loose the state of cells. If use @StateObject then a cell view won't react on a new view model because @StateObject initialiser has an @autoclosure
@SwiftyPlace
@SwiftyPlace 2 жыл бұрын
I think it is good to show simple cases for a beginner level tutorial. But it seems you are looking for more advanced discussion. I might do an example with multiple views that share data between them. Mostly by view models. Just to see the flow of data with @StateObject on the top level and @ObservedObject for all child views. Maybe talking about how to connect multiple view models together. Did you have any problems with this topic in particular?
@bobgodwinx
@bobgodwinx 3 жыл бұрын
Aahahah :) Have fun coding 😂
How To Choose Mac N Cheese Date Night.. 🧀
00:58
Jojo Sim
Рет қаралды 109 МЛН
УДИВИЛ ВСЕХ СВОИМ УХОДОМ!😳 #shorts
00:49
StateObject vs ObservedObject | SwiftUI
19:35
Code Effectively
Рет қаралды 495
5 Steps to Better SwiftUI Views
31:19
Paul Hudson
Рет қаралды 56 М.
How to use @ObservableObject and @StateObject in SwiftUI | Bootcamp #50
35:12