iOS 17 Data Flow with Observation Framework

แชร์
ฝัง

ความคิดเห็น • 79

  • @BuildingRainbows
    @BuildingRainbows ปีที่แล้ว +7

    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  ปีที่แล้ว +2

      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 หลายเดือนก่อน

    Brilliant explanation, thank you very much

    • @StewartLynch
      @StewartLynch  หลายเดือนก่อน

      Glad it was helpful!

  • @pieterbikkel
    @pieterbikkel ปีที่แล้ว +1

    very clear explanation! Keep up the good work!

  • @prblydev
    @prblydev 8 หลายเดือนก่อน

    I've finally(finally..) grasped the concept of environment and observation🥳 Thank you so much!!

  • @gakkieNL
    @gakkieNL 5 หลายเดือนก่อน

    The Observation framework is a huge improvement on the old situation. I expect a fix for the Environment situation in the future ... Great vid!

  • @hung-chuntsai4063
    @hung-chuntsai4063 ปีที่แล้ว

    Always appreciate all your great and intuitive example for walkthrough the Observation framework 🙏

  • @AlanRick26
    @AlanRick26 6 หลายเดือนก่อน

    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.

  • @andrejkling3886
    @andrejkling3886 ปีที่แล้ว +1

    Thank you Stewart 💯

  • @porroapp
    @porroapp 9 หลายเดือนก่อน

    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  9 หลายเดือนก่อน

      Glad it was helpful!

  • @stephaniewagstaff6563
    @stephaniewagstaff6563 ปีที่แล้ว +1

    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.

  • @larschristiansen3136
    @larschristiansen3136 ปีที่แล้ว

    Very useful introduction to this change.

  • @milossavkovic1970
    @milossavkovic1970 ปีที่แล้ว +1

    Awesome explanation Stewart! Its clear, and steady which helps me as a beginner. Keep it going, I’ve just subscribed 🎉

  • @devhopes
    @devhopes 10 หลายเดือนก่อน

    Awesome video, as always, Stewart. Thank you so much for sharing :)

  • @mario_luis_dev
    @mario_luis_dev 6 หลายเดือนก่อน

    amazing content Stewart! Crystal clear explanations, earned my sub for sure!

    • @StewartLynch
      @StewartLynch  6 หลายเดือนก่อน

      Welcome aboard!

  • @larschristiansen3136
    @larschristiansen3136 ปีที่แล้ว +4

    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  ปีที่แล้ว +3

      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 9 หลายเดือนก่อน

      @@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.

  • @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 😄

  • @rebellious_703
    @rebellious_703 ปีที่แล้ว

    Awesome. I like the way you explain things, Please keep it up!

  • @jcpazos65
    @jcpazos65 ปีที่แล้ว

    Thanks Stewart. Great teaching

  • @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.

  • @larryburris6761
    @larryburris6761 ปีที่แล้ว +1

    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  ปีที่แล้ว +3

      I will likely do something like this later in the year.

  • @SinghalRishi27
    @SinghalRishi27 5 หลายเดือนก่อน

    Thank you so much for this ☺

  • @bobwint8114
    @bobwint8114 11 หลายเดือนก่อน

    Awesome as always, thank-you!

  • @allenwixted1992
    @allenwixted1992 11 หลายเดือนก่อน

    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  11 หลายเดือนก่อน +1

      SwiftData is a persistence layer that already uses the Observation framework.

  • @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

  • @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  ปีที่แล้ว +1

      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 TH-cam 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  ปีที่แล้ว +1

      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…

  • @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.

  • @guenter.engelhard
    @guenter.engelhard ปีที่แล้ว

    Thank you!

  • @AndrewDChristie
    @AndrewDChristie 5 หลายเดือนก่อน

    Thanks!

    • @StewartLynch
      @StewartLynch  5 หลายเดือนก่อน

      Thank you very much

  • @ar_transilvania
    @ar_transilvania 5 หลายเดือนก่อน

    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?

  • @josethadeu
    @josethadeu ปีที่แล้ว

    Valeu!

  • @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  ปีที่แล้ว +1

      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 7 หลายเดือนก่อน

      @@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 7 หลายเดือนก่อน

      @@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 7 หลายเดือนก่อน

      @@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.

  • @Vineeth-n3o
    @Vineeth-n3o 9 หลายเดือนก่อน

    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  9 หลายเดือนก่อน

      Yes, as long as it is observed in all of the views. You could inject it into the environment.

  • @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.

  • @kirilldanchenko1385
    @kirilldanchenko1385 8 หลายเดือนก่อน

    Why should I ever consider using @Bindable if @State works just fine in its place?

    • @StewartLynch
      @StewartLynch  8 หลายเดือนก่อน +1

      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 8 หลายเดือนก่อน

      @@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 8 หลายเดือนก่อน

      As far as I get it, I should only use @Bindable in cases where @State is not enough

    • @StewartLynch
      @StewartLynch  8 หลายเดือนก่อน +3

      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 8 หลายเดือนก่อน

      @@StewartLynch That is a great answer. Thank you again!

  • @ipeerless6717
    @ipeerless6717 6 หลายเดือนก่อน

    @Binding is not used instead of @ObservaedObject not correct

    • @StewartLynch
      @StewartLynch  6 หลายเดือนก่อน

      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 6 หลายเดือนก่อน

      @@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  6 หลายเดือนก่อน

      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 6 หลายเดือนก่อน

      @@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  6 หลายเดือนก่อน

      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

  • @AlanRick26
    @AlanRick26 6 หลายเดือนก่อน

    Thanks!

    • @StewartLynch
      @StewartLynch  6 หลายเดือนก่อน

      Thank you very much

  • @AndrewDChristie
    @AndrewDChristie 9 หลายเดือนก่อน

    Thanks!

    • @StewartLynch
      @StewartLynch  9 หลายเดือนก่อน

      Thank you again