SwiftUI 2.0: MVVM - A Practical Approach

Поделиться
HTML-код
  • Опубликовано: 12 дек 2024

Комментарии • 105

  • @bigmtnstudio
    @bigmtnstudio 4 года назад +32

    What a fantastic video! I get new devs asking me all the time about SwiftUI and architecture and now I have a great video to refer them to! I loved the visual approach you took to explain it at the beginning and the code demo for the second half. 👏
    New subscriber 👍

    • @BeyondOnesAndZeros
      @BeyondOnesAndZeros  4 года назад +2

      Wow, I'm a huge fan of your content! Your visual approach to teaching definitely inspired me. I really appreciate your support 😊

    • @bigmtnstudio
      @bigmtnstudio 4 года назад +2

      ​@@BeyondOnesAndZeros , ha ha, nice! It's like we came full circle. I shared this video on my Twitter feed too. Are you on there? If so, let me know your user name.

    • @BeyondOnesAndZeros
      @BeyondOnesAndZeros  4 года назад +2

      ​@@bigmtnstudio exactly! haha I created one just now: "OnesBeyond" I saw your post, thank you for sharing! 😊👍

  • @danno5645
    @danno5645 4 года назад +16

    MVVM Is something that has confused me. I’ve done several tutorials before, but I think I actually understand it now after your video. This is the best example I have seen.

  • @BravoDesign88
    @BravoDesign88 3 года назад

    This video does a great job explaining MVVM thank you. Please continue making more videos because they are really well done.

  • @tunatimetina
    @tunatimetina Год назад

    I've been so stuck on this, and now it clicks. Thank you!!

  • @bkajebeukseb4726
    @bkajebeukseb4726 4 года назад +1

    Most concrete explanation I've seen. Clear and easy to understand. Well done. Teaching abstract ideas can be tough and this made it easy to comprehend. Thanks

  • @yokohibarashi1386
    @yokohibarashi1386 3 года назад

    Completely understood at high level the importance and how to make use of MVVM in SwiftUI. Thank you very much.

  • @daraghmacgabhann1005
    @daraghmacgabhann1005 3 года назад +2

    Best explanation and worked example of MVVM in SwiftUI by far! I was struggling to understand how to separate and access model and view model until I watched this video, I watched multiple other videos but they confused me even more! Thanks so much for breaking it down.

  • @necmettin_solmaz
    @necmettin_solmaz 3 года назад

    Harika bir video. Mvvm ile ilgili çok video izledim ama en iyisi buydu. Sade ve anlaşılır bir biçimde anlatmışsınız. Thank you very much.

  • @joeprince7509
    @joeprince7509 4 года назад +5

    Very simple and clear explanation of MVVM, thank you! The examples you are providing with real world scenarios are great for people learning the new process.

    • @BeyondOnesAndZeros
      @BeyondOnesAndZeros  4 года назад +1

      Thank you, Joe! That was indeed my intention with this videos, glad you agree 👍

  • @samurai7938
    @samurai7938 4 года назад +1

    Best video I have seen explaining MVVM. Thank you so much.

  • @mountrat
    @mountrat 3 года назад

    In India, we often use the word "Guru" (in tamil) for a teacher who teaches in a best way. So... From now onwards, You are my Guru (குரு) (Teacher). :) ♥ 😍

  • @jiabowang7560
    @jiabowang7560 3 года назад

    This is the easiest video I have seen explaining mvvm

  • @JDo9000
    @JDo9000 3 года назад +1

    This really helped! Waaaay clearer than any other videos I saw on RUclips

  • @vorapons5172
    @vorapons5172 3 года назад +1

    Thank you for simple and easy explanation of MVVM

  • @xxfkee
    @xxfkee 4 года назад +1

    Thanks a lot for your clear and step-by-step explanation about MVVM. I finally ended up with clear understanding of this programming notion.

  • @Mahadev-x7u
    @Mahadev-x7u 4 года назад +1

    Great explanation... Gratitude.

  • @iliailiev908
    @iliailiev908 4 года назад +8

    Exactly what I was looking for as a beginner lesson. Thanks bro!

  • @BruceCichowlas
    @BruceCichowlas 3 года назад

    That's simple and clear! Sometimes this the complexity of protocols is added, particularly where one might want to substitute models or view models for purposes of alternate functionality or testing. However, I think it is good to leave that out in a tutorial of this level. Perhaps it is explained in an additional tutorial.

  • @9988khan
    @9988khan 4 года назад +7

    impressive tutorial that cleared my confusion about mvvm, looking for more interesting tutorials from you 👍🏻

  • @tikhonnnnn
    @tikhonnnnn 4 года назад +1

    That’s great! I didn't understand anything about swiftui logic for a long time and now I realised. Thanks!

  • @beemercycle
    @beemercycle 3 года назад +1

    Great tutorial. Kept is simple and all in one file THANKS!

  • @naytebeck3186
    @naytebeck3186 3 года назад +1

    This was a really well put together video dude 👍 Thanks

  • @GolfGuns
    @GolfGuns 3 года назад +1

    Thanks for this. It was a very clear and specific example.

  • @dmitriykhan2011
    @dmitriykhan2011 3 года назад

    Brilliant! Too pity that this channel does not have any new updates for a long time.

  • @TheMadG007
    @TheMadG007 3 года назад +1

    Thank you very much, exactly what I wanted to know in an short example, with no unnecessary bla... bla ... ;o)

  • @nataliiagetlin3611
    @nataliiagetlin3611 3 года назад

    Thank you! So clear and concise. High-quality content!

  • @batuhankrbb
    @batuhankrbb 4 года назад +2

    It's one of the best lessons I've ever taken. Thanks!

  • @yazidali7071
    @yazidali7071 3 года назад +1

    Amazing video and amazing explanation, thank you very much.
    I'm a subscriber now 😁👍

  • @brettandjacob4704
    @brettandjacob4704 3 года назад +1

    This is such a great tutorial that makes perfect sense! Great job!!

  • @willasaskara
    @willasaskara 3 года назад

    very clear explanation and to the point tutorial, thanks!

  • @CredoAcademy
    @CredoAcademy 4 года назад +6

    Great tutorial indeed! 👍

  • @yotzincastrejon
    @yotzincastrejon 3 года назад +1

    Great explanation!

  • @megaBreezy
    @megaBreezy 4 года назад +2

    Fantastic work!

  • @johnpill1
    @johnpill1 2 года назад

    This is an excellent explanation!

  • @ekkogaming5461
    @ekkogaming5461 3 года назад +1

    brooooo... BEST TUTORIAL. Really well done I subscribed!! why you stopped doing videos?

    • @BeyondOnesAndZeros
      @BeyondOnesAndZeros  3 года назад +1

      Thanks, Ekko! I’m actually uploading a video right now, it should be available in the next few hours :D

  • @thecuriouspunjabi
    @thecuriouspunjabi 3 года назад

    neat and clean explanation:-)

  • @johnr.5475
    @johnr.5475 3 года назад

    Really useful. Thanks.

  • @ryankanno2562
    @ryankanno2562 3 года назад

    Awesome video! Thank you!

  • @notorioustofu3482
    @notorioustofu3482 2 года назад

    Great video!

  • @anuragwhocodes5383
    @anuragwhocodes5383 4 года назад +1

    Thanks dude, Subscribed!

  • @605dave
    @605dave 4 года назад +1

    Very helpful, thank you.

  • @rafeeq1410
    @rafeeq1410 3 года назад +1

    @BeyondOnesAndZeros It may be a silly question. At the start of presentation you shows that Model represents Data&Logic, But while in coding the date math logic you did in ViewModel. I am bit confuse here, are we going to keep the logic in Model or ViewModel?

    • @DavidNitzscheBell
      @DavidNitzscheBell 3 года назад +1

      At the beginning, he's talking about functions that pertain to a model, such as "chooseCard()" or "addHealth()" or whatever. But, the logic necessary to convert the Date variable into an Age integer, that goes in the ViewModel, because it's taking the data from the pure Model and massaging/preparing it for the View to use. That's the theory, at least.

  • @magicinternetmoney8715
    @magicinternetmoney8715 2 года назад

    Excellently explained like your other videos! Liked and subscribed, of course.
    One question for you: Any reason why you call the vm method "Intent" as opposed to method?

  • @perrygupta
    @perrygupta 3 года назад +1

    Thanks for this

  • @jorgepezzuol1088
    @jorgepezzuol1088 4 года назад +1

    Great tutorial.
    I have a question regarding the validation of the fields. That would go inside the view model?

    • @BeyondOnesAndZeros
      @BeyondOnesAndZeros  4 года назад +1

      Thanks Jorge, great question! The validation "logic" itself can be considered a model but the actual validation (using the validator model) should happen in the viewModel.
      I recently worked on a project where I had to do some TextField validation (+ inline errors) and I ended up using Combine for it. I will try to create a tutorial for it! :)

    • @jorgepezzuol1088
      @jorgepezzuol1088 4 года назад

      Thanks, that would be great

  • @mika_chu
    @mika_chu 3 года назад

    Thank you! Great tutorial!!! What happens if the data is downloaded from the network? What is the path/ process in such case?

  • @Idlyravva
    @Idlyravva 4 года назад

    Nice and clean

  • @DavidNitzscheBell
    @DavidNitzscheBell 3 года назад

    9:47 Suddenly there's a "Change Name" button in the Preview, but not in the code.... Oops.

  • @marshallross
    @marshallross 3 года назад

    So helpful!

  • @kimjiyoung8655
    @kimjiyoung8655 2 года назад

    thank you, helps a lot. 😘

  • @drmucahiderdogan
    @drmucahiderdogan 3 года назад

    Can you explain the memory issue of using @ObservedObject wrapper and initializing the VM in the properties a little more?

  • @andrei-un3yr
    @andrei-un3yr 3 года назад

    what if your view displays a list of person model objects? Does your viewmodel translate each of the person objects into a separate model that's more easily accessible by the view?

  • @brilliantaksan
    @brilliantaksan 3 года назад

    I think the syntax for the bindings such as @StateObject and @ObservableObject, and if so what are the current ones? and how do they differ, ik i can just search it up on google but I might as well comment about this

  • @wagmun
    @wagmun 3 года назад

    Perfect!

  • @denniswhite6779
    @denniswhite6779 4 года назад

    great presentation... why did you not use the getter/setter pattern when changing the name? do they not work with @StateObject and @Published?

    • @BeyondOnesAndZeros
      @BeyondOnesAndZeros  4 года назад +1

      Hi Dennis, you're absolutely right. You could just use a getter and setter for the name. It would not be an issue with the property wrappers either. However, in more complex apps your intent will be often a function that does a bit more than just changing a property value.

  • @LeeCasey
    @LeeCasey 4 года назад

    Good video. One question. Say on a larger scale project as a game. You’d have models for player, monsters etc. Would they share one view model file/class or would there be playerViewModel & monsterViewModel? Thanks.

    • @BeyondOnesAndZeros
      @BeyondOnesAndZeros  4 года назад +1

      A good rule of thumb is to say you have one viewModel per screen. That one viewModel may interact with different models (player, monsters etc.).

    • @LeeCasey
      @LeeCasey 4 года назад

      @@BeyondOnesAndZeros thanks for replying. That makes sense now.

  • @vell0cet517
    @vell0cet517 3 года назад

    So the ViewModel is basically identical to a Controller, except the view drives the changes instead of the controller?

  • @immanueldiaz5710
    @immanueldiaz5710 4 года назад

    Also I think that if we follow MVVM more we can create 2 more classes like an Repository and a DataSource to get the data from an external API or a local data from a database and a third class that will be the WebService

    • @BeyondOnesAndZeros
      @BeyondOnesAndZeros  4 года назад +1

      Hi Immanuel, good point however you could argue that this is a particular use case and not necessary to use MVVM. Nevertheless, I will soon create a video on Networking/Data accessing with MVVM as well :)

    • @immanueldiaz5710
      @immanueldiaz5710 4 года назад

      @@BeyondOnesAndZeros great work man!!

  • @최승기-g8f
    @최승기-g8f 3 года назад

    Thank you!!!

  • @mika_chu
    @mika_chu 3 года назад

    Why Model is a Source of Truth while the Alice instance is actually stored in ViewModel?

  • @galaxiegalaxie5003
    @galaxiegalaxie5003 4 года назад +1

    thanks for the video,here is the scenario,you go from home to setting screen,and suppose you changed something say language in setting screen and now you go back and it need to reflect on home,how you do that,could you make a video about it😁

    • @BeyondOnesAndZeros
      @BeyondOnesAndZeros  4 года назад

      You’re welcome! Sure will add it to my list. Thanks for your suggestion.

  • @johncarson3333
    @johncarson3333 4 года назад +2

    Boss!!!

  • @natureloverspakistan
    @natureloverspakistan 3 года назад

    where i can add api requests

  • @simonbachmann2120
    @simonbachmann2120 4 года назад

    Is it good practice to have one view model per model or is the view model more like a store that aggregates many models?

    • @BeyondOnesAndZeros
      @BeyondOnesAndZeros  4 года назад +1

      Hi Simon, it is quite common that one viewModel configures multiple different models. However, if you have a more complex view hierarchy like charts and news in one screen, you would have one viewModel for the charts and one viewModel for the news. And each of them would work with multiple models that are relevant for that specific view.

  • @sipanhazim4128
    @sipanhazim4128 4 года назад +1

    great

  • @SwiftyPlace
    @SwiftyPlace 3 года назад

    I think it would be better to place the model and the view model in a different file.

    • @BeyondOnesAndZeros
      @BeyondOnesAndZeros  3 года назад +1

      Yes, you’re right! I usually mention that at the beginning of the video. It’s just easier to explain if you do not have to switch between files a lot ;)

  • @johnybaby9574
    @johnybaby9574 3 года назад +1

    cool

  • @DavidNitzscheBell
    @DavidNitzscheBell 3 года назад

    Maybe the example is just too simplistic, but I don't understand why the struct Person can't have a computed variable, age, rather than creating a class ContentViewModel, etc.
    I'm reading and watching videos and looking at code, and I'm still not really understanding how/why MVVM is *vastly* different from MVC.
    Can't you put all the logic that would be in the ViewModel in the Controller? Why is that different? People talk about MVC stands for "Massive View Controller", but wouldn't any logic in there necessarily be in the ViewModel, too? How/why is a ViewModel going to have *less* code?
    Why, for instance, does the Person struct not have an Age computed variable? Is it really necessary to create a ContentViewModel for that?
    I'm looking for examples where the ViewModel provides something essential that is not possible with MVC or a computed variable. These examples are kind of useful, but not convincing.

  • @erwin.agpasa
    @erwin.agpasa 6 месяцев назад

    Power

  • @vvvorlds
    @vvvorlds 5 месяцев назад

    How ist this not MVC???

  • @bunkie2100
    @bunkie2100 3 года назад

    Calling the model “the source of truth” is misleading. This is because the model is only a *definition* , not a source of data or state, The source of truth is the *instance* of the model declared and maintained by the view model.