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 , 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.
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.
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
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.
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.
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). :) ♥ 😍
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.
@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?
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.
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?
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! :)
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?
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
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.
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.
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
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 :)
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😁
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.
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 ;)
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.
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.
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 👍
Wow, I'm a huge fan of your content! Your visual approach to teaching definitely inspired me. I really appreciate your support 😊
@@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.
@@bigmtnstudio exactly! haha I created one just now: "OnesBeyond" I saw your post, thank you for sharing! 😊👍
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.
Thanks Danno, great to hear that!
yes bro me also
This video does a great job explaining MVVM thank you. Please continue making more videos because they are really well done.
I've been so stuck on this, and now it clicks. Thank you!!
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
Thanks Bkaje, appreciate your feedback! :)
Completely understood at high level the importance and how to make use of MVVM in SwiftUI. Thank you very much.
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.
Great to hear that! You’re welcome, Daragh!
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.
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.
Thank you, Joe! That was indeed my intention with this videos, glad you agree 👍
Best video I have seen explaining MVVM. Thank you so much.
Thanks, glad it was helpful! :)
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). :) ♥ 😍
This is the easiest video I have seen explaining mvvm
This really helped! Waaaay clearer than any other videos I saw on RUclips
Great to hear that, thanks Jeffrey!
Thank you for simple and easy explanation of MVVM
You're welcome Voraapon, great to hear that!
Thanks a lot for your clear and step-by-step explanation about MVVM. I finally ended up with clear understanding of this programming notion.
Awesome! Great to hear that fkeebie :)
Great explanation... Gratitude.
Exactly what I was looking for as a beginner lesson. Thanks bro!
You’re welcome!
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.
impressive tutorial that cleared my confusion about mvvm, looking for more interesting tutorials from you 👍🏻
Awesome, thank you! Glad it cleared up the confusion :)
That’s great! I didn't understand anything about swiftui logic for a long time and now I realised. Thanks!
Awesome, glad it was helpful! :)
Great tutorial. Kept is simple and all in one file THANKS!
This was a really well put together video dude 👍 Thanks
Thanks for this. It was a very clear and specific example.
You're welcome! :) glad it was helpful
Brilliant! Too pity that this channel does not have any new updates for a long time.
Thank you very much, exactly what I wanted to know in an short example, with no unnecessary bla... bla ... ;o)
Thank you! So clear and concise. High-quality content!
It's one of the best lessons I've ever taken. Thanks!
Thanks, Batuhan! Good to hear that :)
Amazing video and amazing explanation, thank you very much.
I'm a subscriber now 😁👍
Thanks, Yazid!
This is such a great tutorial that makes perfect sense! Great job!!
very clear explanation and to the point tutorial, thanks!
Great tutorial indeed! 👍
Great explanation!
Thanks Yotzin!
Fantastic work!
This is an excellent explanation!
brooooo... BEST TUTORIAL. Really well done I subscribed!! why you stopped doing videos?
Thanks, Ekko! I’m actually uploading a video right now, it should be available in the next few hours :D
neat and clean explanation:-)
Really useful. Thanks.
Awesome video! Thank you!
Great video!
Thanks dude, Subscribed!
Awesome, thanks Anurag!
Very helpful, thank you.
@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?
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.
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?
Thanks for this
You’re welcome! :)
Great tutorial.
I have a question regarding the validation of the fields. That would go inside the view model?
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! :)
Thanks, that would be great
Thank you! Great tutorial!!! What happens if the data is downloaded from the network? What is the path/ process in such case?
Nice and clean
9:47 Suddenly there's a "Change Name" button in the Preview, but not in the code.... Oops.
So helpful!
thank you, helps a lot. 😘
Can you explain the memory issue of using @ObservedObject wrapper and initializing the VM in the properties a little more?
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?
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
Perfect!
great presentation... why did you not use the getter/setter pattern when changing the name? do they not work with @StateObject and @Published?
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.
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.
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.).
@@BeyondOnesAndZeros thanks for replying. That makes sense now.
So the ViewModel is basically identical to a Controller, except the view drives the changes instead of the controller?
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
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 :)
@@BeyondOnesAndZeros great work man!!
Thank you!!!
Why Model is a Source of Truth while the Alice instance is actually stored in ViewModel?
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😁
You’re welcome! Sure will add it to my list. Thanks for your suggestion.
Boss!!!
where i can add api requests
Is it good practice to have one view model per model or is the view model more like a store that aggregates many models?
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.
great
Thanks! :)
I think it would be better to place the model and the view model in a different file.
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 ;)
cool
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.
Power
How ist this not MVC???
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.