SwiftUI 2.0: MVVM - A Practical Approach

  Рет қаралды 32,599

BeyondOnesAndZeros

BeyondOnesAndZeros

Күн бұрын

Пікірлер: 105
@bigmtnstudio
@bigmtnstudio 4 жыл бұрын
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 жыл бұрын
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 жыл бұрын
​@@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 жыл бұрын
​@@bigmtnstudio exactly! haha I created one just now: "OnesBeyond" I saw your post, thank you for sharing! 😊👍
@danno5645
@danno5645 3 жыл бұрын
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.
@BeyondOnesAndZeros
@BeyondOnesAndZeros 3 жыл бұрын
Thanks Danno, great to hear that!
@bijendersinghshekhawat6842
@bijendersinghshekhawat6842 2 жыл бұрын
yes bro me also
@tunatimetina
@tunatimetina Жыл бұрын
I've been so stuck on this, and now it clicks. Thank you!!
@BravoDesign88
@BravoDesign88 3 жыл бұрын
This video does a great job explaining MVVM thank you. Please continue making more videos because they are really well done.
@necms
@necms 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 жыл бұрын
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 жыл бұрын
Thank you, Joe! That was indeed my intention with this videos, glad you agree 👍
@bkajebeukseb4726
@bkajebeukseb4726 3 жыл бұрын
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
@BeyondOnesAndZeros
@BeyondOnesAndZeros 3 жыл бұрын
Thanks Bkaje, appreciate your feedback! :)
@JDo9000
@JDo9000 3 жыл бұрын
This really helped! Waaaay clearer than any other videos I saw on KZbin
@BeyondOnesAndZeros
@BeyondOnesAndZeros 3 жыл бұрын
Great to hear that, thanks Jeffrey!
@daraghmacgabhann1005
@daraghmacgabhann1005 3 жыл бұрын
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.
@BeyondOnesAndZeros
@BeyondOnesAndZeros 3 жыл бұрын
Great to hear that! You’re welcome, Daragh!
@iliailiev908
@iliailiev908 4 жыл бұрын
Exactly what I was looking for as a beginner lesson. Thanks bro!
@BeyondOnesAndZeros
@BeyondOnesAndZeros 4 жыл бұрын
You’re welcome!
@jiabowang7560
@jiabowang7560 3 жыл бұрын
This is the easiest video I have seen explaining mvvm
@samurai7938
@samurai7938 4 жыл бұрын
Best video I have seen explaining MVVM. Thank you so much.
@BeyondOnesAndZeros
@BeyondOnesAndZeros 4 жыл бұрын
Thanks, glad it was helpful! :)
@yokohibarashi1386
@yokohibarashi1386 3 жыл бұрын
Completely understood at high level the importance and how to make use of MVVM in SwiftUI. Thank you very much.
@vorapons5172
@vorapons5172 3 жыл бұрын
Thank you for simple and easy explanation of MVVM
@BeyondOnesAndZeros
@BeyondOnesAndZeros 3 жыл бұрын
You're welcome Voraapon, great to hear that!
@batuhankrbb
@batuhankrbb 3 жыл бұрын
It's one of the best lessons I've ever taken. Thanks!
@BeyondOnesAndZeros
@BeyondOnesAndZeros 3 жыл бұрын
Thanks, Batuhan! Good to hear that :)
@tikhonnnnn
@tikhonnnnn 4 жыл бұрын
That’s great! I didn't understand anything about swiftui logic for a long time and now I realised. Thanks!
@BeyondOnesAndZeros
@BeyondOnesAndZeros 4 жыл бұрын
Awesome, glad it was helpful! :)
@beemercycle
@beemercycle 3 жыл бұрын
Great tutorial. Kept is simple and all in one file THANKS!
@xxfkee
@xxfkee 3 жыл бұрын
Thanks a lot for your clear and step-by-step explanation about MVVM. I finally ended up with clear understanding of this programming notion.
@BeyondOnesAndZeros
@BeyondOnesAndZeros 3 жыл бұрын
Awesome! Great to hear that fkeebie :)
@andrejkling3886
@andrejkling3886 3 жыл бұрын
Great explanation... Gratitude.
@TheMadG007
@TheMadG007 3 жыл бұрын
Thank you very much, exactly what I wanted to know in an short example, with no unnecessary bla... bla ... ;o)
@9988khan
@9988khan 4 жыл бұрын
impressive tutorial that cleared my confusion about mvvm, looking for more interesting tutorials from you 👍🏻
@BeyondOnesAndZeros
@BeyondOnesAndZeros 4 жыл бұрын
Awesome, thank you! Glad it cleared up the confusion :)
@nataliiagetlin3611
@nataliiagetlin3611 3 жыл бұрын
Thank you! So clear and concise. High-quality content!
@brettandjacob4704
@brettandjacob4704 3 жыл бұрын
This is such a great tutorial that makes perfect sense! Great job!!
@dmitriykhan2011
@dmitriykhan2011 3 жыл бұрын
Brilliant! Too pity that this channel does not have any new updates for a long time.
@GolfGuns
@GolfGuns 3 жыл бұрын
Thanks for this. It was a very clear and specific example.
@BeyondOnesAndZeros
@BeyondOnesAndZeros 3 жыл бұрын
You're welcome! :) glad it was helpful
@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.
@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). :) ♥ 😍
@naytebeck3186
@naytebeck3186 3 жыл бұрын
This was a really well put together video dude 👍 Thanks
@willasaskara
@willasaskara 3 жыл бұрын
very clear explanation and to the point tutorial, thanks!
@yotzincastrejon
@yotzincastrejon 3 жыл бұрын
Great explanation!
@BeyondOnesAndZeros
@BeyondOnesAndZeros 3 жыл бұрын
Thanks Yotzin!
@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?
@johnpill1
@johnpill1 2 жыл бұрын
This is an excellent explanation!
@megaBreezy
@megaBreezy 4 жыл бұрын
Fantastic work!
@CredoAcademy
@CredoAcademy 4 жыл бұрын
Great tutorial indeed! 👍
@yazidali7071
@yazidali7071 3 жыл бұрын
Amazing video and amazing explanation, thank you very much. I'm a subscriber now 😁👍
@BeyondOnesAndZeros
@BeyondOnesAndZeros 3 жыл бұрын
Thanks, Yazid!
@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?
@johnr.5475
@johnr.5475 3 жыл бұрын
Really useful. Thanks.
@notorioustofu3482
@notorioustofu3482 2 жыл бұрын
Great video!
@rafeeq1410
@rafeeq1410 3 жыл бұрын
@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 жыл бұрын
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.
@jorgepezzuol1088
@jorgepezzuol1088 4 жыл бұрын
Great tutorial. I have a question regarding the validation of the fields. That would go inside the view model?
@BeyondOnesAndZeros
@BeyondOnesAndZeros 4 жыл бұрын
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
@ryankanno2562
@ryankanno2562 3 жыл бұрын
Awesome video! Thank you!
@ekkogaming5461
@ekkogaming5461 3 жыл бұрын
brooooo... BEST TUTORIAL. Really well done I subscribed!! why you stopped doing videos?
@BeyondOnesAndZeros
@BeyondOnesAndZeros 3 жыл бұрын
Thanks, Ekko! I’m actually uploading a video right now, it should be available in the next few hours :D
@perrygupta
@perrygupta 3 жыл бұрын
Thanks for this
@BeyondOnesAndZeros
@BeyondOnesAndZeros 3 жыл бұрын
You’re welcome! :)
@thecuriouspunjabi
@thecuriouspunjabi 3 жыл бұрын
neat and clean explanation:-)
@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
@drmucahiderdogan
@drmucahiderdogan 3 жыл бұрын
Can you explain the memory issue of using @ObservedObject wrapper and initializing the VM in the properties a little more?
@marshallross
@marshallross 2 жыл бұрын
So helpful!
@vell0cet517
@vell0cet517 3 жыл бұрын
So the ViewModel is basically identical to a Controller, except the view drives the changes instead of the controller?
@LeeCasey
@LeeCasey 3 жыл бұрын
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 3 жыл бұрын
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 3 жыл бұрын
@@BeyondOnesAndZeros thanks for replying. That makes sense now.
@605dave
@605dave 4 жыл бұрын
Very helpful, thank you.
@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 жыл бұрын
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.
@anuragwhocodes5383
@anuragwhocodes5383 3 жыл бұрын
Thanks dude, Subscribed!
@BeyondOnesAndZeros
@BeyondOnesAndZeros 3 жыл бұрын
Awesome, thanks Anurag!
@wagmun
@wagmun 3 жыл бұрын
Perfect!
@mika_chu
@mika_chu 3 жыл бұрын
Why Model is a Source of Truth while the Alice instance is actually stored in ViewModel?
@최승기-g8f
@최승기-g8f 3 жыл бұрын
Thank you!!!
@kimjiyoung8655
@kimjiyoung8655 2 жыл бұрын
thank you, helps a lot. 😘
@Idlyravva
@Idlyravva 4 жыл бұрын
Nice and clean
@johnybaby9574
@johnybaby9574 3 жыл бұрын
cool
@sipanhazim4128
@sipanhazim4128 4 жыл бұрын
great
@BeyondOnesAndZeros
@BeyondOnesAndZeros 4 жыл бұрын
Thanks! :)
@johncarson3333
@johncarson3333 4 жыл бұрын
Boss!!!
@erwin.agpasa
@erwin.agpasa 5 ай бұрын
Power
@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 жыл бұрын
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!!
@SwiftyPlace
@SwiftyPlace 3 жыл бұрын
I think it would be better to place the model and the view model in a different file.
@BeyondOnesAndZeros
@BeyondOnesAndZeros 3 жыл бұрын
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 ;)
@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 жыл бұрын
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.
@galaxiegalaxie5003
@galaxiegalaxie5003 3 жыл бұрын
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 3 жыл бұрын
You’re welcome! Sure will add it to my list. Thanks for your suggestion.
@natureloverspakistan
@natureloverspakistan 3 жыл бұрын
where i can add api requests
@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.
@DavidNitzscheBell
@DavidNitzscheBell 3 жыл бұрын
9:47 Suddenly there's a "Change Name" button in the Preview, but not in the code.... Oops.
@vvvorlds
@vvvorlds 4 ай бұрын
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.
SwiftUI 2.0 + Combine - Getting Started (2020)
28:20
BeyondOnesAndZeros
Рет қаралды 24 М.
Human vs Jet Engine
00:19
MrBeast
Рет қаралды 182 МЛН
When mom gets home, but you're in rollerblades.
00:40
Daniel LaBelle
Рет қаралды 127 МЛН
SwiftUI MVVM | A Realistic Example
16:46
Kilo Loco
Рет қаралды 32 М.
SwiftUI Tutorial - Weather App (MVVM, JSON API, CoreLocation)
38:32
8 Common SwiftUI Mistakes - and how to fix them!
28:05
Paul Hudson
Рет қаралды 50 М.
SwiftUI 2.0: Core Data - How To Use Core Data From Scratch (2020)
25:40
BeyondOnesAndZeros
Рет қаралды 31 М.
SwiftUI 2.0: In-App Purchase - Getting Started From Scratch (2020)
52:25
BeyondOnesAndZeros
Рет қаралды 14 М.