How to use @ObservableObject and @StateObject in SwiftUI | Bootcamp #50

Поділитися
Вставка
  • Опубліковано 27 жов 2024

КОМЕНТАРІ • 195

  • @daraghmacgabhann1005
    @daraghmacgabhann1005 3 роки тому +74

    Your course is excellent, beats all others I've seen hands down! Your course/videos clearly show how to use the different items with thoughtful examples and explanations. This video explains what I found to be the most confusing, when to use @StateObject and @ObservableBbject. Looking forward to the Environment video. Thank you for taking the time and effort to create this course, it sets the gold standard!

    • @SwiftfulThinking
      @SwiftfulThinking  3 роки тому +1

      Thanks Daragh! I really appreciate that. Yes, the @EnvironmentObject is next... if you understood this video, the next one should be a breeze. Thanks for watching :)

  • @picabloo
    @picabloo 2 роки тому +24

    I am SO happy I found your channel. Amazing quality. Great clear communication, sympathy for newbies, explaining everything, quality mic, everything. Thanks for all your hard work!

    • @vazzhh
      @vazzhh 9 місяців тому

      So do I

  • @Wiintb
    @Wiintb 2 роки тому +16

    Nick. I am a CTO who was trying to learn Swift for fun. I had visited a lot of material and I find your approach to be the best. Beats even the paid materials by a long distance.
    My best wishes and do let me know how we can help contribute to you besides referring.
    You should be hitting at least 100K viewers.

  • @sols.2525
    @sols.2525 3 роки тому +11

    I have been watching your videos for a few days now. I also watch some others content creators as well. Out of all the ones I watch I find yours to be excellent and unique. You are the first person to actually make videos explaining each thing in great detail. All the others just build apps that get followed with maybe some explaining. Thats great too but this is helping me learn so much better.... So Thank You for making all of these and I hope you never stop!

    • @SwiftfulThinking
      @SwiftfulThinking  3 роки тому +2

      Wow! Thanks for the comment Scott. That's really appreciated. I'm very happy to help. Let me know if you have any questions!

  • @nevemra5
    @nevemra5 Рік тому +2

    Perfect, perfect, perfect!
    Every day I learn from your videos. You were not the first in my path, but by far the best. I have never understood complex topics so easily, as I began to understand with you. Clear beautiful speech allows me to understand you (English is not my native language). I'm very happy that I found you. I feel that one mug of coffee will not be enough)) The material costs a whole mountain of mugs of coffee

  • @filipp7236
    @filipp7236 7 місяців тому +2

    You're the best, dude! I've been doing this Hacking with Swift course, but I was so confused with the fundamentals, and you are explaining it so simply! I'm very grateful. Thanks.

    • @Wallax92
      @Wallax92 Місяць тому

      I started with the Hacking with Swift course too, but when I read the challenge on Day 35 I wasn't confident enough to try complete them, so I started to look for another course & found this one. He explains things so well!

  • @jlambert12013
    @jlambert12013 Рік тому +1

    Best explanation of these property wrappers. I’ve spent months trying to grasp managing state and it has been so confusing. This tutorial wasn’t so overly complicated like so I actually grasped the concepts. This entire channel is GOLD!

  • @rajdhakate617
    @rajdhakate617 2 роки тому +1

    Man really solved my doubt about @StateObject and @ObservedObject. Please make sure videos like these. It’s amazing

  • @manishparihar3361
    @manishparihar3361 Рік тому +1

    Finally i got clear concept of why, when and where we can use Identifiable, ObservaleObject, @StateObject, @ObservedObject. Thank you Nick

  • @ehsanbaghaki
    @ehsanbaghaki 2 роки тому +1

    I have watched over 10 different tutorials on youtube around this concept, you have explained this concept much much much better and cleaner and underestandable than any other tutorial. Thanks a lot!

  • @coldy5845
    @coldy5845 3 місяці тому

    Thank you Nick. Your videos are still being watched. Very very clear and thoughtful explanation of everything. Ofc it has to be watched maybe twice in order to absorb everything properly but such a video i can watch even 4 times! Keep up the good work!

  • @bbulliard
    @bbulliard 2 роки тому +1

    I love the way you explained the diff between @state and observable object. So abundantly clear

  • @ScaleCodingSkills
    @ScaleCodingSkills 2 роки тому +1

    I started working on SwiftUI and I got stuck at @State and @StateObject, I found your video on the @StateObject, I found this very helpful and now I am planning to learn SwiftUI from your playlist instead of other platforms. Thanks for creating excellent content.

  • @bbulliard
    @bbulliard 2 роки тому +4

    You do such an absolute great job explaining the code. I will now have to give you the title, SMSMI (supreme master swift mentor and instructor). Thanks for a world class video. Bob

    • @SwiftfulThinking
      @SwiftfulThinking  2 роки тому

      Haha that's a new one 😂 Glad you're enjoying the Bootcamp!

  • @AllanZhang16
    @AllanZhang16 11 місяців тому +1

    What a great video. Perfect pacing, perfect explanations, and I like how you reinforce important concepts. Thanks again.

  • @solomonrajkumar5537
    @solomonrajkumar5537 2 роки тому +1

    your boot camp is incredible awesome!!!

  • @pazuzutru-truluv7094
    @pazuzutru-truluv7094 2 роки тому

    Once again I must thank you for this video. It explains things so well where as other videos, that got me started, excluded key points and ended up in a mess when I attempted to create the project I have been tasked with.
    I am just about to embark on updating my app and feel confident that this has got me over the rather confused situation I had ended up in. I almost feel guilty for getting all your tutorage for free and hope you are generating some revenue from this marvellous series.
    Thank you once again!

  • @tamasterjek7520
    @tamasterjek7520 3 роки тому +2

    First video I watched from you. Great explanation, easy to understand. Now I have to watch your other videos too :)

    • @SwiftfulThinking
      @SwiftfulThinking  3 роки тому

      Welcome to the channel Tamas! I hope you like them :)

  • @sundayreading
    @sundayreading Рік тому

    Proud coffee member on a monthly basis now🥳. Please do not stop teaching!

  • @muhammadusman-vc5re
    @muhammadusman-vc5re Рік тому +4

    Not only describe the concept in a straightforward way but also tells the use cases of real projects. GOD bless on you.

  • @stepanivanov6877
    @stepanivanov6877 2 роки тому +1

    Thank you Nick. You explained how to use @StateObject and @ObservedObject perfectly.

  • @maguirer
    @maguirer 3 роки тому +2

    Another great video, Nick! This is probably the most crucial one to date in the Bootcamp series, IMHO. I have a feeling I'll be coming back to it again several times. I've watched a lot of the WWDC videos, but they still left me a bit confused on what the difference was between @StateObject and @ObservedObject and when to use one over the other. In fact, I think I had them backwards in my head, but this video has helped them click into place.

    • @SwiftfulThinking
      @SwiftfulThinking  3 роки тому +1

      I'm very happy to help this. This was confusing for me as well when I was learning. Once you understand it, it's actually pretty easy to implement. It's definitely important though because we will use these for all of our ViewModels in MVVM architecture!

    • @itsAJ819
      @itsAJ819 2 роки тому

      Im in the same boat. I've been watching videos on @StateObject and @ObservedObject from other creators and they left me extremely confused. Though, after watching Nick's videos on @StateObject and @ObservedObject once, its a bit clearer. Ill still have to come back and watch it a few times. Other topics, he cleared up in 1 shot for me. Nick has my favorite creator for swiftUI. I wish I watched these videos before tackling DogGram though. But once I'm done here, ill redo it.

  • @SergeiKeyVee
    @SergeiKeyVee 3 роки тому +4

    Thank you so much! I finally got it. Amazing video)

  • @stefanlindholm3284
    @stefanlindholm3284 2 роки тому +1

    This was very well explained! Thank you Nick!

  • @olepetersen4460
    @olepetersen4460 3 роки тому +3

    Brilliant - you just cleared up for me, why my app reloaded data at times, when I did not want it. And what to do about it. Many thanks.

  • @ConfidentlyRong-jo5yt
    @ConfidentlyRong-jo5yt 4 місяці тому

    Can't thank you enough for demystifying the difference between @State & @StateObject , @ObservableObject & @ObservedObject and when to use each one respectively. Thanks bro! Also thanks for introducing me to the ProgressView() 😎

    • @SwiftfulThinking
      @SwiftfulThinking  4 місяці тому +1

      You’re on #50 already? Beast mode 🚀🚀🚀

  • @jameshawley2745
    @jameshawley2745 2 роки тому +1

    Dude these tutorials are amazing! Keep up the good work!

  • @tigran.zakaryan
    @tigran.zakaryan Рік тому +1

    Great explanation!
    Thank you👍👍👍👍

  • @gregh528
    @gregh528 Рік тому +1

    Great video. Thanks Nick.

  • @alanmaloney2791
    @alanmaloney2791 6 місяців тому

    Brilliant video! Wonderfully clear and perfectly explained👍👍👍

  • @rafaelclaycon
    @rafaelclaycon 2 роки тому +1

    Omg, you gave me the missing piece I was looking for! Thank you so much! Great content!

  • @ataberkkilinctekin188
    @ataberkkilinctekin188 2 роки тому

    This video explains a lot about the @ObservableObject and @StateObject. I literally learned what those are and how they are used. Thanks a lot for this video. :)

  • @mustafasabahy3092
    @mustafasabahy3092 Рік тому

    please don't stop you make life easier and more simple ♥

  • @PengyGoy
    @PengyGoy 2 дні тому

    Watching a ton of your videos - thank you!

  • @idrissben1613
    @idrissben1613 Рік тому

    thank you it's by far the best explanation i found for this subject!

  • @SwiftUIBootCampSachi
    @SwiftUIBootCampSachi 8 місяців тому

    Thanks from the bottom of my Heart Mate ❤💚

  • @andresraigoza2082
    @andresraigoza2082 2 роки тому +1

    Wonderful explanation!!! Thank you so much for investing your time making this videos.

  • @bbulliard
    @bbulliard 2 роки тому

    Wonderful for understanding state, stateobj and observable object. Thanks a bunch

  • @Dragonboh1
    @Dragonboh1 10 місяців тому

    keep doing what you doing man

  • @aloksinha2688
    @aloksinha2688 2 роки тому

    Your explanation techniques is unique and simple..I love it. 👍

  • @aleksandertesenkov1421
    @aleksandertesenkov1421 9 місяців тому

    Excellent video. Wonderful explanation. I knew most of this stuff but I learned many small details.

  • @douglasfers7
    @douglasfers7 10 місяців тому

    Dud you're amazing! Thanks a lot!

  • @maciusessa
    @maciusessa 2 роки тому

    Great vid as always. Keep it up! Loving this content and leaving comments to make your YT algorithm better!

    • @SwiftfulThinking
      @SwiftfulThinking  2 роки тому

      Thank you Tomek! That’s very much appreciated 🥳

  • @HeyoSlick
    @HeyoSlick 7 місяців тому

    This video saved my life. Thank you.

  • @いろい-b2l
    @いろい-b2l Рік тому +3

    Additional notes for Swift beginners:
    * At 14:08. If the code is too long, you can remove ': FruitViewModel' from the var declaration, because type of the var is always FruitViewModel.

    • @redax3866
      @redax3866 Рік тому +1

      Do not do this. This will worsen the readability of the code.

    • @NICK4LIFE11
      @NICK4LIFE11 10 місяців тому

      The type is inferred from the assignment. Saying it will worsen the readability is your opinion. @@redax3866

  • @mamazur
    @mamazur 3 роки тому

    All courses are amazing. You are the best.

    • @SwiftfulThinking
      @SwiftfulThinking  3 роки тому

      Thank you for watching :)))

    • @mamazur
      @mamazur 3 роки тому

      @@SwiftfulThinking Nick your course is super. But if you have time can you make another video about Picker. It is not working, especially label. And by the way how to make picker with optional value. I think about such pickier but I don't know how to make it In such nice and user friendly look like you do. Thanks for all. The best iOS course on internet is yours. You are legend.

  • @benceylan273
    @benceylan273 3 роки тому +2

    Hey Nick, thanks for another amazing video. I said that many times but will say here again; I watched bunch of tutorials about @ObservableObject, @ObservedObject and @StateObject but this is the first time I understood the logic. Your teaching method is just awesome.

    • @SwiftfulThinking
      @SwiftfulThinking  3 роки тому +1

      Thanks for the comment Ben! Hearing that makes this all worth it for me. I'm glad this video helped 🥳

  • @valerieokelly6224
    @valerieokelly6224 2 роки тому

    Top quality course 😍

  • @OGLerma
    @OGLerma 2 роки тому

    Amazing explanation! Love all your videos. I was a little confused before and this kinda cleared everything up.

  • @zcaur7329
    @zcaur7329 2 роки тому

    What a well done video ! Kudos to you !

  • @johnr.5475
    @johnr.5475 3 роки тому +1

    Another excellent video. Thanks very much. It’s very well explained.

  • @maria_chemerys
    @maria_chemerys 9 місяців тому

    Thank you! You are our lifesaver❤

  • @adamkacha3823
    @adamkacha3823 2 роки тому

    Great explanation. Thank you so much!

  • @Nunny25
    @Nunny25 3 роки тому +1

    Great explanation, thanks

  • @farescherni6946
    @farescherni6946 3 роки тому

    sir congratulations you have the best course covering swiftui

    • @SwiftfulThinking
      @SwiftfulThinking  3 роки тому +1

      Wow, haha. I don't know if it's the best, but I'm very glad you're liking it! 🙃

  • @burakbozdoganli
    @burakbozdoganli Рік тому

    Excellent lessons !

  • @morreke
    @morreke 2 роки тому

    Very well explained !!

  • @youngdomsey
    @youngdomsey 5 місяців тому

    Great course! :)

  • @heshamabdo6024
    @heshamabdo6024 Рік тому

    There are so many great ideas in this video
    thnk you

  • @r_celikkaya
    @r_celikkaya 3 роки тому

    I discovered you a few ago . I think that your videos is useful very .Thanks.

  • @dineshdas9983
    @dineshdas9983 Рік тому

    Sooo good explanation thanks mate🎉👍

  • @rmjalejandro
    @rmjalejandro Рік тому

    Nick i've finished both swift and swiftui bootcamp, came back to this vid to grasp a little bit more on this, thank you for your good work, please let us know if you have a site to "Buy you a coffee" or somehow retribute some of the knowledge you've given to us.

    • @SwiftfulThinking
      @SwiftfulThinking  Рік тому

      I’m glad these videos helped! I do have a BuyMeACoffee: www.buymeacoffee.com/nicksarno
      Thanks 🍻

  • @mig12394
    @mig12394 3 роки тому

    Thanks a lot very clear with an exhaustif example

  • @danielcovaci6930
    @danielcovaci6930 Рік тому

    great tutorial, keep up the good work

  • @최승기-g8f
    @최승기-g8f 3 роки тому

    Great Video. Thank you !!!

  • @muqadasali8288
    @muqadasali8288 2 роки тому

    Oh man you are a great teacher
    love from Pakistan

  • @MarianaLaic
    @MarianaLaic Рік тому

    Thank U! I am new on programming

  • @juich337
    @juich337 2 роки тому

    The Best! Thanks!

  • @OttoFaerber
    @OttoFaerber 3 роки тому

    Great, your teaching method is very understandable and helps me a lot, thanks a lot

  • @scottw1734
    @scottw1734 3 роки тому

    Really well explained :)

  • @zhong2341
    @zhong2341 2 роки тому

    Thank you so much for great explanations

  • @kauekaj
    @kauekaj Рік тому

    Awesome! 👏

  • @MohamedAli-kg5im
    @MohamedAli-kg5im Рік тому

    thanks man, fantastic video

  • @Raahim
    @Raahim 2 роки тому

    very well explained!

  • @sema_f
    @sema_f 2 роки тому

    We ❤️ to hang with u here! 🥳

  • @unknownerror999
    @unknownerror999 6 місяців тому +1

    Nick, thank you so much for your lessons, do you have core data lessons? i did't find it

    • @SwiftfulThinking
      @SwiftfulThinking  6 місяців тому

      Yes, they are in the Continued Learning playlist. You can also search “core” across all videos here: www.swiftful-thinking.com/search

  • @kurtschmucker4229
    @kurtschmucker4229 2 роки тому +1

    During this video, I expected you to move the FruitViewModel class to its own file, but you didn't. Are you just delaying the "separate files" concept until a later video? A separate file seems like the logical organization for the code.

    • @SwiftfulThinking
      @SwiftfulThinking  2 роки тому

      Yes, the ViewMode would normally have its own file. I just don’t always create separate files in the videos because it’s easier to organize / display in the tutorial. Moving that code to another file wouldn’t change the actual implementation though!

  • @MikeyGio777
    @MikeyGio777 2 роки тому

    Very Good!!!

  • @williamwildsmith5162
    @williamwildsmith5162 2 роки тому

    Quick question Nick...
    Why have both a FruitModel struct, and a FruitViewModel class?
    Why not just have a FruitModel class?
    Sorry, if it's a dumb question!
    Thank you

  • @ado9678
    @ado9678 13 днів тому

    @State = @StateObject : @Binding = @ObservedObject. Major difference is @StateObject & @ObservedObject are for instances of your class whereas @State & @Binding are more for your variables. Also, after doing some tinkering with the code I found that having a property with @ObservedObject will not reinitialize the object every time you step away and return to the screen as Nick had said, maybe it happens when you deal with more screens, not sure

  • @ChristianPichardo-k5w
    @ChristianPichardo-k5w Рік тому +1

    quick question. If I wanted to ensure that the data persists when that application is closed , would I need to save the information in coreData?

  • @peterellison8306
    @peterellison8306 3 роки тому +2

    Would it be possible to say something more about the "@Environment(\.presentationMode) var presentationMode" line? It is kind of a black box to me.

    • @SwiftfulThinking
      @SwiftfulThinking  3 роки тому +1

      I will add a video on the @Environment to this playlist in the next few weeks. Thanks for the idea!

  • @Raahim
    @Raahim 2 роки тому

    underrated

  • @mithatucar1593
    @mithatucar1593 3 роки тому +1

    OMG thx so much.I have been struggling about how the fuck updating data works

  • @ilyaparaskevich3154
    @ilyaparaskevich3154 Рік тому +1

    Your tutorials are amazing, but I’ve noticed you have some problems with naming. According to the Apple guidelines you’d better use
    var fruits: [Fruit] = []
    instead of
    var fruitArray: [FruitModel] = []
    Words ‘array’ and ‘model’ are redundant.

    • @SwiftfulThinking
      @SwiftfulThinking  Рік тому +1

      Good point.. I only do this so that it’s easier to understand for new learners

  • @elliotknight5552
    @elliotknight5552 2 роки тому

    My brain is burning lmao thanks for videos bro btw

  • @ShooMPozitiV
    @ShooMPozitiV 2 роки тому

    Nick, we all need your help about initialization of StateObjects. Please, can you explain about initialization of it? When my view getting parameters on init, which I need to initialize StateObject? What i have to do? I heard somewhere, that initialization of StateObject in init of view - is not good idea. But it's very often case. I'm looking information about it, but nothing ...

  • @diniezikry3121
    @diniezikry3121 3 роки тому +2

    Yo! So is it possible for the SecondView to update the information regarding the fruits (eg. changing the fruit count) in the first view?

    • @SwiftfulThinking
      @SwiftfulThinking  3 роки тому +2

      Yo!! Yes! That's the magic behind all of this. We are using the same ViewModel for all of the views. So if you update it in one place, it will automatically update everywhere. Because the data is @Published, it "published" the change to all of the views that are observing it!

  • @dugrut1325
    @dugrut1325 2 роки тому

    this is beyond me, I'll have to start all over, or get 'boot' out. haha... I started back at Bootcamp #1 🤣

  • @JZ-xc8hu
    @JZ-xc8hu Рік тому

    thank you very much

  • @sadeqnoori8707
    @sadeqnoori8707 3 роки тому

    Super! thx man

  • @dmitriyfedorov5728
    @dmitriyfedorov5728 2 роки тому

    Hey Nick, thank you for the amazing video - it is very handy. I have maybe a dumb question. If you refactor the entire List into a separate struct and then use the reference to this struct in your home view. Where should @StateObject be? In the home view, right?

  • @thetrinitysolution9631
    @thetrinitysolution9631 3 роки тому +1

    So in essence, when you write, _"var fruitViewModel: FruitViewModel = FruitViewMode()l,"_ you're instantiating an object of the "FruitViewModel" class. Is that correct?

    • @SwiftfulThinking
      @SwiftfulThinking  3 роки тому +2

      Yes, when you add the () at the end of FruitViewModel(), you are calling the init() function within the FruitViewModel class to initialize a new object!

  • @jalapisco
    @jalapisco Рік тому

    Thanks again for an excellent video. You did (as always) and excellent job explaining classes. I do have a question though, in SwiftUI what is the difference between structures and classes; they look pretty similar at first glance (I don't know if classes can also be used to create views but other than that one may think they can be used interchangeably).

    • @SwiftfulThinking
      @SwiftfulThinking  Рік тому

      Hey! This is not a beginner topic, but everything you need to know about structs vs classes is here: ua-cam.com/video/-JLenSTKEcA/v-deo.html

    • @jalapisco
      @jalapisco Рік тому

      @@SwiftfulThinking Thanks for your response. I had a quick glance at the video and realize that it is too advanced for me so I'll be patience and wait until I get there.

    • @SwiftfulThinking
      @SwiftfulThinking  Рік тому

      @@jalapisco haha for right now, just know that in SwiftUI, all of your Views must be structs and your ViewModels (or any ObservableObject) must be a class. Your data models can be either, but usually are structs.

  • @Mike-er2ih
    @Mike-er2ih 6 місяців тому

    Is it common and good practice in iOS Dev to pass viewModels around like that? Shouldn't RandomScreen (and each screen) basically have it's own ViewModel? And both ViewModels would access data from a common data storage which would be located lower in the general app architecture?

  • @osi0.111
    @osi0.111 2 роки тому

    you are the best

  • @eddydon1929
    @eddydon1929 2 роки тому +1

    can you make a video on firebase or Vapor

  • @itmeocon25
    @itmeocon25 Рік тому

    Thank you your video. How to use button delete instead onDelete() for List ?

  • @theflutterguy6301
    @theflutterguy6301 4 місяці тому

    good stuff

  • @TheSpiralnotizblock
    @TheSpiralnotizblock 2 роки тому

    I think your title might be wrong. Should it not be "How to use ObservableObject and @StateObject in SwiftUI | Bootcamp" wihtout the @, because ObservableObject is the protocol.