Hey Stewart! Probably not easy to fix, but I think the arrow at 04:19 is pointing to the wrong variable? Should be 'number', not 'name'. LOVE your content. Thanks so much for producing it!
@StewartLynch Жыл бұрын
Oops. Good catch. You are right though. The only way to fix it is to upload a new video and that would break the link. I will pin your comment.
@Mhak-rt3lu2 ай бұрын
Brilliant explanation, thank you very much
@StewartLynch2 ай бұрын
Glad it was helpful!
@prblydev9 ай бұрын
I've finally(finally..) grasped the concept of environment and observation🥳 Thank you so much!!
@pieterbikkel Жыл бұрын
very clear explanation! Keep up the good work!
@StewartLynch Жыл бұрын
Thanks, will do!
@devhopes11 ай бұрын
Awesome video, as always, Stewart. Thank you so much for sharing :)
@hung-chuntsai4063 Жыл бұрын
Always appreciate all your great and intuitive example for walkthrough the Observation framework 🙏
@AlanRick268 ай бұрын
The section at 24:24 is worth its weight in gold. Many thanks. Totally agree with your suggestion to Apple. I was flummoxed until I watched your video.
@mario_luis_dev8 ай бұрын
amazing content Stewart! Crystal clear explanations, earned my sub for sure!
@StewartLynch8 ай бұрын
Welcome aboard!
@rebellious_703 Жыл бұрын
Awesome. I like the way you explain things, Please keep it up!
@StewartLynch Жыл бұрын
Thanks, will do!
@porroapp11 ай бұрын
Have just started using swift coming from react and typescript. Must say the new changes in observation framework really makes it much more simpler. This makes injecting dependencies into child views a lot more maintainable and allows me to write less code. Thank u for this excellent explanation of this new feature! It will save me a lot of time when building new apps! ❤
@StewartLynch11 ай бұрын
Glad it was helpful!
@Mahadev-x7u Жыл бұрын
Thank you Stewart 💯
@gakkieNL7 ай бұрын
The Observation framework is a huge improvement on the old situation. I expect a fix for the Environment situation in the future ... Great vid!
@larschristiansen3136 Жыл бұрын
Very useful introduction to this change.
@bobwint8114 Жыл бұрын
Awesome as always, thank-you!
@jcpazos65 Жыл бұрын
Thanks Stewart. Great teaching
@Shane-rh3wu Жыл бұрын
Great video, thanks! Helped me glue together why, in the apple example projects, they are using @Bindable in the View body 😄
@tech_ch1211 Жыл бұрын
Thank you Stewart for your fantastic efforts, I want to contribute my humble understanding to observation property wrappers (after experiments with migrating legacy code): an object declared with @State is equivalent to @StateObject before. No wrapper before the object (var) is equivalent to @ObservedObject before. If you need to bind a property of an Observable: In case the Observable is defined with @State we can use ($)object.property In the second case, we need to add @Bindable to var and use ($)object.property I hope this helps clarify things.
@stephaniewagstaff6563 Жыл бұрын
Thank you so much.! I’ve been wanting to get on this but really needed to make sure I understood how it worked first and as always you did an excellent job providing that.
@StewartLynch Жыл бұрын
Glad it helped!
@milossavkovic1970 Жыл бұрын
Awesome explanation Stewart! Its clear, and steady which helps me as a beginner. Keep it going, I’ve just subscribed 🎉
@StewartLynch Жыл бұрын
Glad you think so.
@larryburris6761 Жыл бұрын
Excellent video, as always!! Would it be possible to provide a tutorial where data is downloaded from a web service, stored in model objects and displayed in a view? I'm having difficulty saving the retrieved data to the database in a database manager since the model context required for saving the data can only be accessed inside of a view. I would like to adhere to best practices regarding separation of concerns, if possible. Any advice would be greatly appreciated!
@StewartLynch Жыл бұрын
I will likely do something like this later in the year.
@SentimentalMo Жыл бұрын
Thank you very much! This is very nice! It's so confusing as I learn this: Binding, @Binding, @Bindable, easy to fix all these up. My Xcode 15b6 doesn't auto compile the view body when I type in struct Foo: View { }, compile fixit insert "typealias VIew ...", not var body
@ar_transilvania7 ай бұрын
How can you propagate a logout or login change from within a subview toggle in the appstate environment object without injecting it in every subview?
@SinghalRishi277 ай бұрын
Thank you so much for this ☺
@guenter.engelhard Жыл бұрын
Thank you!
@StewartLynch Жыл бұрын
You're welcome!
@larschristiansen3136 Жыл бұрын
Thank you Stewart for this very nice introduction to @Observable. It lays out the new, simpler way , of using @State, @Binding @Environment and @Bindable. It will be a great improvement over the old ObservableObject. And as a bonus ContentUnavailableView, really super handy in many contexts. I'm looking forward to future videos on @Observable in more complicated contexts. Quick comment on the previous question. The MVVM pattern with ObservableObject does add a layer between the class with the user data and the user interface. I would imagine that the @Observable macro would work in a similar context.
@StewartLynch Жыл бұрын
You can use MVVM with @Observable as well, but there are some limitations. For example, you cannot use @AppStorage within a class that uses @Observable macro. I will eventually cover an work around though.
@porroapp11 ай бұрын
@@StewartLynchperhaps that’s by design? I.E app storage should not be used in MVVM? I’m just getting into the architecture and have come across MV as this is how Apple build their demo apps.
@AndrewDChristie10 ай бұрын
Thanks!
@StewartLynch10 ай бұрын
Thank you again
@allenwixted1992 Жыл бұрын
Total novice question, but how does this relate to the Swift Data and Model macro? As I’m working on a new app, I don’t mind targeting the latest release, should I ignore this amazing explanation and move straight to using Model?
@StewartLynch Жыл бұрын
SwiftData is a persistence layer that already uses the Observation framework.
@obelix8477 Жыл бұрын
@13:55 wish you'd explain how to use the Extract Subview command. You've given so many hints for streamlining work flow, but not extracting subviews. 😜
@StewartLynch Жыл бұрын
I seldom if ever use it as I find it easier to do it manually. Half the time the extract subView does not work for me and it places the subview in a location I do not want and I end up having to rename it.
@yourbestsail Жыл бұрын
Hello! Great video. Just an important question. Why are you using @State for the User custom type at the beginning in the first example, when Apple in their video of WWDC clearly say that you shouldn’t use it with the new Observation Framework? You can just use “user” as a variable without any wrapper in front. @State should be used exclusively if part of the view and if bindings are necessary.
@StewartLynch Жыл бұрын
Yup. you are absolutely correct. @State was not necessary until I added the toggle to the isHappy property after which I need to use @State. Thanks for pointing this out. I already have a pinned comment so I can't pin yours to the top. I wish there were a way to edit KZbin videos and maintain the url.
@yourbestsail Жыл бұрын
@@StewartLynch Thanks a lot for your prompt answer Stewart!! ☺️ Anyway I have to say that Apple didn’t make it crystal clear the usage. I mean, when before ios17 I had to use @StateObject, can I know omit any wrapper? And when passing an object that before I had to declare as @ObservedObject in a child view, now I can use nothing too? Is Observation framework managing ownerships automatically? Thanks!
@StewartLynch Жыл бұрын
The best way to figure this out is to try it without any macro (not a property wrapper) and see if you get any errors thrown. If you don't then you likely do not need it.
@yourbestsail Жыл бұрын
@@StewartLynch Yeah, I suppose that most is done under the hood with the new framework…
@malamin Жыл бұрын
Quick question: How does this new framework work with MVVM? In iOS 16, I would create a Model struct and a ViewModel ObservableObject class to handle the model logic. Now, models are Observable classes. Where does the ViewModel logic to manipulate the model go? a new class? the existing model class? is MVVM still even relevant?
@StewartLynch Жыл бұрын
You can use @Observable the same way as you used ObservableObject with MVVM.
@indiekiduk Жыл бұрын
MVVM was never relevant to SwiftUI because the View struct is a view model already so you don't need any objects.
@w0mblemania9 ай бұрын
@@indiekiduk Not really. It's often better to keep a View as simple as possible, and put related logic out in to another object: the View Model.
@indiekiduk9 ай бұрын
@@w0mblemania in Swift logic goes in funcs not objects. That way you prevent the shared mutable state problem Swift and SwiftUI was designed to fix.
@w0mblemania9 ай бұрын
@@indiekiduk MMm, I think that's a bit theoretical. In every day Swift we put logic in to objects all the time. Functions have containers, and associated data all the time, after all. There's nothing wrong with using View Models and references to data managers, stores. In fact, it's the norm. Shared mutable state better served by containerisation and isolation through things like actors.
@kirilldanchenko13859 ай бұрын
Why should I ever consider using @Bindable if @State works just fine in its place?
@StewartLynch9 ай бұрын
YOu need to use Bindable if you are injecting an object from another view or the environment. a State object is for a single view only and will not update values in other views.
@kirilldanchenko13859 ай бұрын
@@StewartLynch Ah, now I see. Before, I did not run the app and only used the preview where everything looked perfectly. Now that I’ve run the app with @State instead of @Bindable, I’ve got this violet error telling "Accessing State's value outside of being installed on a View. This will result in a constant Binding of the initial value and will not update." Thanks for the explanation!
@kirilldanchenko13859 ай бұрын
As far as I get it, I should only use @Bindable in cases where @State is not enough
@StewartLynch9 ай бұрын
No. That is not it at all. @State is only used to initialize an observed object if it is only used within that View. If the object is an observed object created elsewhere and is being used in the view it must be @Bindable
@kirilldanchenko13859 ай бұрын
@@StewartLynch That is a great answer. Thank you again!
@josethadeu Жыл бұрын
Valeu!
@StewartLynch Жыл бұрын
Merci Beaucoup
@Vineeth-n3o11 ай бұрын
I have 3 views. Grandparent Parent Child Child contains the textField component and variable name is textInput. I want to pass the textInput value to parent and from parent to grandparent. Can I use Observable Object?
@StewartLynch10 ай бұрын
Yes, as long as it is observed in all of the views. You could inject it into the environment.
@ipeerless67177 ай бұрын
@Binding is not used instead of @ObservaedObject not correct
@StewartLynch7 ай бұрын
I just rewatched that video, and I don’t see where I said that. Can you give me a time stamp? @StateObject -> @ObservedObject but now, @State for an observed object -> @Bindable. @Binding and @Bindable are different
@ipeerless67177 ай бұрын
@@StewartLynch at 00.38 second at the begining of video @BIndable is instead of @observedObject if that correct ?it also instead of @EnvironmentObject or any subview of view or instance of struct or class also ? i think all of them one way binding not two ways binding like new @Bindable . about difference between @Bindable , @Binding is clear thanks for your great content
@StewartLynch7 ай бұрын
u can inject State objects which are oberved into the environment. As I show at the end of the video, if you want to be alble to update a proprety in an Environment State object, you will need to introduce Bindable into your view and assign the State object to the variable with the Bindable property wrapper. I don’t see where there are any mistakes in my explanation, but if so, I would really like to clear it up.
@ipeerless67177 ай бұрын
@@StewartLynch new property wrapper @Bindable is two ways binding but @ObservedObject is one way binding they are not alternatives for each other u said at 38 second of video first minute
@StewartLynch7 ай бұрын
I think you are incorrect here. I have a sample project that I would be happy to send to you if you want to reach out to me by email to continue this conversation. It clearly demonstrates the parallels between @State/Observation framework -> @Bindable and @StateObject/@ObservableObject -> @ObservedObject
@victorriurean Жыл бұрын
@nuka1195 Жыл бұрын
Helpful video as usual. :) There seems to be a bug at least with Xcode 15 beta 6. Whenever you toggle isLoggedIn. It goes back to tab 1.