iOS 17 Data Flow with Observation Framework

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

Stewart Lynch

Stewart Lynch

Күн бұрын

Пікірлер: 79
@BuildingRainbows
@BuildingRainbows Жыл бұрын
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
@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-rt3lu
@Mhak-rt3lu 2 ай бұрын
Brilliant explanation, thank you very much
@StewartLynch
@StewartLynch 2 ай бұрын
Glad it was helpful!
@prblydev
@prblydev 9 ай бұрын
I've finally(finally..) grasped the concept of environment and observation🥳 Thank you so much!!
@pieterbikkel
@pieterbikkel Жыл бұрын
very clear explanation! Keep up the good work!
@StewartLynch
@StewartLynch Жыл бұрын
Thanks, will do!
@devhopes
@devhopes 11 ай бұрын
Awesome video, as always, Stewart. Thank you so much for sharing :)
@hung-chuntsai4063
@hung-chuntsai4063 Жыл бұрын
Always appreciate all your great and intuitive example for walkthrough the Observation framework 🙏
@AlanRick26
@AlanRick26 8 ай бұрын
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_dev
@mario_luis_dev 8 ай бұрын
amazing content Stewart! Crystal clear explanations, earned my sub for sure!
@StewartLynch
@StewartLynch 8 ай бұрын
Welcome aboard!
@rebellious_703
@rebellious_703 Жыл бұрын
Awesome. I like the way you explain things, Please keep it up!
@StewartLynch
@StewartLynch Жыл бұрын
Thanks, will do!
@porroapp
@porroapp 11 ай бұрын
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! ❤
@StewartLynch
@StewartLynch 11 ай бұрын
Glad it was helpful!
@Mahadev-x7u
@Mahadev-x7u Жыл бұрын
Thank you Stewart 💯
@gakkieNL
@gakkieNL 7 ай бұрын
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
@larschristiansen3136 Жыл бұрын
Very useful introduction to this change.
@bobwint8114
@bobwint8114 Жыл бұрын
Awesome as always, thank-you!
@jcpazos65
@jcpazos65 Жыл бұрын
Thanks Stewart. Great teaching
@Shane-rh3wu
@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
@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
@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
@StewartLynch Жыл бұрын
Glad it helped!
@milossavkovic1970
@milossavkovic1970 Жыл бұрын
Awesome explanation Stewart! Its clear, and steady which helps me as a beginner. Keep it going, I’ve just subscribed 🎉
@StewartLynch
@StewartLynch Жыл бұрын
Glad you think so.
@larryburris6761
@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
@StewartLynch Жыл бұрын
I will likely do something like this later in the year.
@SentimentalMo
@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_transilvania
@ar_transilvania 7 ай бұрын
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?
@SinghalRishi27
@SinghalRishi27 7 ай бұрын
Thank you so much for this ☺
@guenter.engelhard
@guenter.engelhard Жыл бұрын
Thank you!
@StewartLynch
@StewartLynch Жыл бұрын
You're welcome!
@larschristiansen3136
@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
@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.
@porroapp
@porroapp 11 ай бұрын
@@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.
@AndrewDChristie
@AndrewDChristie 10 ай бұрын
Thanks!
@StewartLynch
@StewartLynch 10 ай бұрын
Thank you again
@allenwixted1992
@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
@StewartLynch Жыл бұрын
SwiftData is a persistence layer that already uses the Observation framework.
@obelix8477
@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
@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
@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
@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
@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
@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
@yourbestsail Жыл бұрын
@@StewartLynch Yeah, I suppose that most is done under the hood with the new framework…
@malamin
@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
@StewartLynch Жыл бұрын
You can use @Observable the same way as you used ObservableObject with MVVM.
@indiekiduk
@indiekiduk Жыл бұрын
MVVM was never relevant to SwiftUI because the View struct is a view model already so you don't need any objects.
@w0mblemania
@w0mblemania 9 ай бұрын
@@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.
@indiekiduk
@indiekiduk 9 ай бұрын
@@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.
@w0mblemania
@w0mblemania 9 ай бұрын
@@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.
@kirilldanchenko1385
@kirilldanchenko1385 9 ай бұрын
Why should I ever consider using @Bindable if @State works just fine in its place?
@StewartLynch
@StewartLynch 9 ай бұрын
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.
@kirilldanchenko1385
@kirilldanchenko1385 9 ай бұрын
@@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!
@kirilldanchenko1385
@kirilldanchenko1385 9 ай бұрын
As far as I get it, I should only use @Bindable in cases where @State is not enough
@StewartLynch
@StewartLynch 9 ай бұрын
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
@kirilldanchenko1385
@kirilldanchenko1385 9 ай бұрын
@@StewartLynch That is a great answer. Thank you again!
@josethadeu
@josethadeu Жыл бұрын
Valeu!
@StewartLynch
@StewartLynch Жыл бұрын
Merci Beaucoup
@Vineeth-n3o
@Vineeth-n3o 11 ай бұрын
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?
@StewartLynch
@StewartLynch 10 ай бұрын
Yes, as long as it is observed in all of the views. You could inject it into the environment.
@ipeerless6717
@ipeerless6717 7 ай бұрын
@Binding is not used instead of @ObservaedObject not correct
@StewartLynch
@StewartLynch 7 ай бұрын
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
@ipeerless6717
@ipeerless6717 7 ай бұрын
@@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
@StewartLynch
@StewartLynch 7 ай бұрын
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.
@ipeerless6717
@ipeerless6717 7 ай бұрын
@@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
@StewartLynch
@StewartLynch 7 ай бұрын
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
@victorriurean Жыл бұрын
@nuka1195
@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.
@AlanRick26
@AlanRick26 8 ай бұрын
Thanks!
@StewartLynch
@StewartLynch 8 ай бұрын
Thank you very much
@AndrewDChristie
@AndrewDChristie 6 ай бұрын
Thanks!
@StewartLynch
@StewartLynch 6 ай бұрын
Thank you very much
Enhancements to ScrollView in iOS 17
23:43
Stewart Lynch
Рет қаралды 7 М.
SwiftUI Property Wrappers
23:20
Stewart Lynch
Рет қаралды 7 М.
I thought one thing and the truth is something else 😂
00:34
عائلة ابو رعد Abo Raad family
Рет қаралды 13 МЛН
Как Я Брата ОБМАНУЛ (смешное видео, прикол, юмор, поржать)
00:59
Creative Justice at the Checkout: Bananas and Eggs Showdown #shorts
00:18
Fabiosa Best Lifehacks
Рет қаралды 32 МЛН
Sigma Kid Mistake #funny #sigma
00:17
CRAZY GREAPA
Рет қаралды 12 МЛН
SwiftUI GeometryReader
27:53
Stewart Lynch
Рет қаралды 12 М.
Enum Navigation in iOS 16
14:19
Stewart Lynch
Рет қаралды 11 М.
How to use @Observable Macro in SwiftUI | Bootcamp #76
18:52
Swiftful Thinking
Рет қаралды 8 М.
@Observable @Bindable in iOS17 - SwiftUI Data Flow
12:22
Rebeloper - Rebel Developer
Рет қаралды 2,4 М.
SwiftUI Alerts - Buttons, TextFields, & Passing Errors
13:18
Sean Allen
Рет қаралды 7 М.
SwiftUI: New Observation Framework
8:25
Mike Mikina
Рет қаралды 2,1 М.
Beat Ronaldo, Win $1,000,000
22:45
MrBeast
Рет қаралды 56 МЛН
Comparing @Observable to ObservableObjects in SwiftUI
12:57
donny wals
Рет қаралды 1,6 М.
What's New in SwiftUI State Management
29:48
azamsharp
Рет қаралды 7 М.
I thought one thing and the truth is something else 😂
00:34
عائلة ابو رعد Abo Raad family
Рет қаралды 13 МЛН