SwiftUI MVVM | A Realistic Example

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

Kilo Loco

Kilo Loco

Күн бұрын

Пікірлер: 85
@HatTerry
@HatTerry 3 жыл бұрын
Bro. After watching this, I feel like I owe you money now. Definitely helped a lot. 🔥
@pqsk
@pqsk 3 жыл бұрын
nice tutorial. straight to the point, no beating around the bush, no 5 minutes of talking randomness and then 20 minutes into the video reiterating that just to make the video a certain length 😂 again thanks for the quick explanation!
@talldane2538
@talldane2538 Жыл бұрын
Kilo's recent postings exude the kind of confidence and completeness I appreciate when trying to learn/use SwiftUI in the real world. His comments especially give you the kind of insight you need when considering completeness (lifecycle). Production is topnotch as well, no more fumbling over errors or mistyping.
@ghazitozri4989
@ghazitozri4989 4 жыл бұрын
this kind of realistic senarios are the best, please feed us more Loco ! good luck
@ssturge963
@ssturge963 3 жыл бұрын
This video was absolutely perfect. Dependency injection with default values, protocols & mocking is how I work right now with UIKit, and your video was perfect for teaching me how to work the same way with SwiftUI. Loved it.
@huntermeyer4972
@huntermeyer4972 4 жыл бұрын
This is great. I'd love to see various example of MVVM with real-world examples of a backend, whether through networking or some sort of persistence manager (I'm thinking Codable, Core Data, etc.) I'd also love a more clear explanation of how to Combine with MVVM in a more powerful way than what was done in this video. Thanks!
@christianschuster4171
@christianschuster4171 4 жыл бұрын
This is the thing we need “real world scenario”. Implementing MVVM and it works, adding a network delay and the preview stops working. Thanks for putting this out! Data flow in this design pattern is a point of interest. A common scenario should be a settings view that changes a app-wide setting which another view has to notice.
@lamehunter
@lamehunter 3 жыл бұрын
best video i watched this year lad good job
@FredLacis
@FredLacis 4 жыл бұрын
Great video! Whenever a project starts to get bigger a problem that I have is on how to organize the architecture and the folder structure, it would be nice to see how you do it, maybe in a real project or something like that!
@Kilo_Loco
@Kilo_Loco 4 жыл бұрын
Working on a real project and the course will be available soon 😉
@shivaskanthan6144
@shivaskanthan6144 4 жыл бұрын
@@Kilo_Loco this sounds promising. Looking forward to it :)
@franciscojavierpriorramos1110
@franciscojavierpriorramos1110 4 жыл бұрын
I am so happy to see another video of you again
@Skolzerx
@Skolzerx 4 жыл бұрын
Nice, I like the idea of using an extension to wrap the view model. Never seen that before but makes alot of sense to me.
@stephanjanuar2923
@stephanjanuar2923 4 жыл бұрын
Best Explanation of MVVM I have seen.
@larryogrodnek6733
@larryogrodnek6733 3 жыл бұрын
Thanks! You’re a great teacher! I really appreciate how you specifically called out how to get things working in previews and how to make it testable,
@Kilo_Loco
@Kilo_Loco 3 жыл бұрын
Glad it was helpful!
@ivanyoed
@ivanyoed 2 жыл бұрын
Great Video Kilo.
@hotskyakash
@hotskyakash 2 жыл бұрын
Excellent explanation Kilo 👏
@thugcow
@thugcow 4 жыл бұрын
Good video! Clean and to the point. Def helps with transitioning from thinking of UIKit MVVM to SwiftUI MVVM.
@abhishekbedi1432
@abhishekbedi1432 2 жыл бұрын
Wonderful! Just what I needed!
@CraigSchubert
@CraigSchubert 2 жыл бұрын
Great video - thanks! I love how you gave the different levels of the concept. More videos like this please!! :-)
@marshallross
@marshallross 2 жыл бұрын
Op! Did I just find my new favorite KZbin?
@danlkramer
@danlkramer 3 жыл бұрын
Very clear explanation and example. Thank you!
@workflowinmind
@workflowinmind 3 жыл бұрын
This is a great approach
@alcprado
@alcprado 3 жыл бұрын
Excellent content, straight and clean. Ty
@podomunro
@podomunro 3 жыл бұрын
Great video. I'd like to see an example where we need to pass the 'Users' from view to view, where each of those views have their own ViewModel. I don't want to be 'fetching' my data each time I initialise a new ViewModel. Thanks :)
@jeraldo4571
@jeraldo4571 2 жыл бұрын
Thanks for this tutorial. It's easier to understand and the pace is spot on. I've been using state based MVVM in UIKit and was wondering how I can use it in SwiftUI.
@kyunghwankim1269
@kyunghwankim1269 2 жыл бұрын
Amazing! Thank you :)
@_WhatsInAName_
@_WhatsInAName_ 3 жыл бұрын
I would really really appreciate a session exactly like this but with DataStore as the main source of data. You mentioned using "data managers" instead of a DataService; is this what you meant? DataStore is a singleton though isn't it? It is sort of available via injection, not via @Environment but via 'import Amplify'. Perhaps I need to learn more about Combine but how would you extract the DataStore.hub.publisher call into a separate DataService class? Can you 'mock' DataStore.hub or should GraphQL calls to it be encapsulated in a DataService for testing the ViewModel?
@salihcnkhy
@salihcnkhy 4 жыл бұрын
It's super, thanks a lot! I would like to see MVVM architecture that build with Combine and SwiftUI frameworks. That would be so cool
@denisblack9897
@denisblack9897 3 жыл бұрын
What’s cool is UIKit and MVC) do the job, stop fooling around
@aaronlabeau1007
@aaronlabeau1007 3 жыл бұрын
Great video!
@jyman
@jyman 4 жыл бұрын
Thanks for your video, it is really helpful to me. Thanks!
@jacques-dev
@jacques-dev 3 жыл бұрын
Hey Kilo! Thanks for the video. Any tips on project file/folder structure?
@abdouett3676
@abdouett3676 4 жыл бұрын
Thank you Kilo Loco!
@Kilo_Loco
@Kilo_Loco 4 жыл бұрын
It’s my pleasure 😁
@hirokiishida375
@hirokiishida375 2 жыл бұрын
Thanks for the content. I saw your other protocol videos but I'm not quite understanding the benefit of introducing protocol here. Could you kindly elaborate on the following?? "It also gives us the flexibility to start testing with like a MockDataService or whatever you want to do there and all this functionality will still work" (11:19)
@hirokiishida375
@hirokiishida375 2 жыл бұрын
Sorry, I understood it by watching this: kzbin.info/www/bejne/oXnXdqd3hZl3hKM
@luism3889
@luism3889 4 жыл бұрын
Great explanation, would be great to see a tutorial of MVVM + CoreData
@alanramirez1031
@alanramirez1031 3 жыл бұрын
Test names need to start with test otherwise Xcode will not detect them, just writing because I know I was having trouble because of that. Great tutorial, thanks.
@DrunkZergling
@DrunkZergling 4 жыл бұрын
Great demo. I found it easy to follow and understand. As a tutorial for people learning MVVM, would it be better to have a more concrete discussion on what problem we're trying to solve? Maybe have an example of a View that has too much business logic in it, and a description of the problems that creates. Then the demo is moving code out of the View into the ViewModel. For me, this sort of conversation about what problem we want to solve is very helpful, especially with examples.
@Kilo_Loco
@Kilo_Loco 4 жыл бұрын
Thanks for the input. That gives me a lot to think about. Will definitely keep that in mind for future videos
@hallux5411
@hallux5411 3 жыл бұрын
@@Kilo_Loco I know I'm late to the party here but I second what he's saying. I found this very helpful and informative but a better structure at the beginning outlining what our goal was with a finished product, a bit more logic going on would make this even better. Thank you for the content!
@lukassbeataddicts
@lukassbeataddicts 3 жыл бұрын
Kilo Loco never disappoints. At the moment I'm trying to build complex reusable networking layer with Combine. Boy it's not the easiest thing. Real life apps usually starts with some sort of intro view then login and then tab view or navigation with lists, sheets and popovers. Every tutorial shows list view with some detail view and trying to teach mvvm. 🤦‍♂️
@miff78
@miff78 3 жыл бұрын
Great short and precise, it would be great if you make similar with MVVM - Coordinator for Swift UI
@abrarwiryawan
@abrarwiryawan 4 жыл бұрын
Cool vid, i hope you do MVVM Compose and how to test them sometime in the future
@NotoriousGarage
@NotoriousGarage 4 жыл бұрын
Thank You for the Christmas gift. 🎄🎅🏽🎄🎁🎁🎁
@eichenherzmo
@eichenherzmo 3 жыл бұрын
This is so freakin great
@olegnaumenko4871
@olegnaumenko4871 2 жыл бұрын
Thank You for this lesson! However, I don't get that manipulation with StateObject() in the init() of the UsersView. In my opinion, that's not needed, because you already did it in the line: "@StateObject var viewModel = ViewModel()". This effectively creates a property of class StateObject with a property wrapper of our view model, and assigns it to var _viewModel. Please correct me if I am wrong. My code is working fine without all this init() thing, even with completion delay in AppDataService.
@burakyildirtan1660
@burakyildirtan1660 Жыл бұрын
Hey Great Video! Greetings from Germany👋🏻 After watching your Video I still have a question left. What if you have multiple VMs / Views and you want to get Data from the network connection ? How do I prevent that I am requesting the data for every VM again?
@stephanusschoeman9413
@stephanusschoeman9413 3 жыл бұрын
This is one of the best explanations of MVVM I've seen since Microsoft started with it in WPF back in the early 2010s. Would you say that data added to the ViewModel should already be processed and business logic not applicable to the view should be kept to a minimum? I think this is where most people run into trouble. They have a light View but the ViewModel suddenly becomes bloated. Thank's Loco Great Video
@acjazz01
@acjazz01 2 жыл бұрын
For small projects may be uncommon using viewmodel in more than one view, but for big projects, it's not. MVVM says that ViewModel must be agnostic, putting inside a view extension you're creating a strong connection between them. Let's say that you have in your project a product viewmodel which lists products of your store (all or filtered). You can have some views that show those products, but in this approach showed in this video, this will fail miserably.
@matrosovdeveloper
@matrosovdeveloper Жыл бұрын
Not sure what the issue with putting viewModel in extension. It is not strong relationship as it is a protocol based viewModel. So you have separate class view which handle UI and you have viewModel which contains business logic. So getUsers will be executed in separate viewModel place and UI will be updated when users array will get new state of values. I don’t see there is any strong relationship. Could you provide code example you are referring as a potential strong connection?
@wesleybritob
@wesleybritob 4 жыл бұрын
Great video, this kind of content makes the difference. If you find a way to change statusBar dynamically please let me know =]
@Kilo_Loco
@Kilo_Loco 4 жыл бұрын
Haven’t tried changing it yet but I’ll look into it 😉
@JamesHaleyRentingAmerica
@JamesHaleyRentingAmerica 3 жыл бұрын
What do you do when you have two ViewModel that you have to use on the same screen?
@rillieux1792
@rillieux1792 3 жыл бұрын
Great video. What should I do to implement the same MMVM patterns with CoreData? I'm not getting the idea with the AppDataService use and the preview injections. Can you give any pointers?
@tranminhhaifet
@tranminhhaifet 3 жыл бұрын
why the preview does not work with DispatchQueue.main.async?
@yisseldarhoc8525
@yisseldarhoc8525 3 жыл бұрын
This is such a useful video, it definitely helped me refactor my project. Can you go more into details about the manager singleton? How would you test the view? How would you add a layer to handle offline mode?
@Kilo_Loco
@Kilo_Loco 3 жыл бұрын
Sure thing! I plan on doing more testing videos in the future github.com/Kilo-Loco/content/issues/29
@yisseldarhoc8525
@yisseldarhoc8525 3 жыл бұрын
@@Kilo_Loco Awesome, looking forward to them :)
@crimsondragon95
@crimsondragon95 3 жыл бұрын
How do you handle error messages via alert? Or updating the view based on changes on the view model?
@seriouslysupersonic
@seriouslysupersonic 3 жыл бұрын
Interesting tutorial. It's funny I also started declaring the ViewModel as an extension of each view on my projects a while back as it helps structuring the code! I wonder however if you shouldn't use the @ObservedObject property wrapper whenever your view receives a view model object that is own by another view. The @StateObject property wrapper also deals with instantiation of an ObservableObject which in this case does not seem to be necessary if you already have a ViewModel object to pass to the init.
@Kilo_Loco
@Kilo_Loco 3 жыл бұрын
Very cool!
@hosseindastan6221
@hosseindastan6221 4 жыл бұрын
thanks. why did u use weak self? in this case ur UsersView is struct and there is no memory leak for struct am i wrong?
@pratamaramadhan9769
@pratamaramadhan9769 4 жыл бұрын
Thanks, kilo! But if you put a loading view while fetching the data, it would be perfect haha
@danielwatson6529
@danielwatson6529 3 жыл бұрын
So ive been using this method for a while and its great. like contentView with a @stateobject - its view model which is an extension. today im playing around with having the content view as an extention of the view model. it seems to work quite well, and eliminates some passing around in a few ov my projects, just wondering if you, or anyone here had tried that out
@alvin3171997
@alvin3171997 3 жыл бұрын
Looks similar to Filedstack MVVM setup for flutter! Gotta learn some iOS development using the same setup :D
@Kilo_Loco
@Kilo_Loco 3 жыл бұрын
There’s a lot of stuff that can be shared between the two since they are both declarative
@sami790311
@sami790311 2 жыл бұрын
Great video! Just one thing - “sot” is actually “sut” system under test.
@TheDancing0wind
@TheDancing0wind 2 жыл бұрын
When testing view model the problem is not the async in the "production" - the problem is that we are not interested in testing API service (and probably a bunch of extra stuff that it depends on). But we still want to have real life like async behaviour. Removing this async behaviour from tests bad. ( xcode has built in test for async results)
@moosegoose1282
@moosegoose1282 3 жыл бұрын
some ppl say use redux. thoughts?
@eldarkk4566
@eldarkk4566 3 жыл бұрын
Hello buddy. Where are you man?
@nebulousJames12345
@nebulousJames12345 3 жыл бұрын
I feel like having a protocol for ViewModel would be better :D
@Kilo_Loco
@Kilo_Loco 3 жыл бұрын
I generally prefer to only use protocols on things that will be reused. Also, dealing with protocols and published properties is kinda messy.
@nebulousJames12345
@nebulousJames12345 3 жыл бұрын
@@Kilo_Loco good to know. I typically always expect views to be reused, because if I dont write them in a manner that they can be reused, they wont be :). I’m coming from reactive swift, so ill definitely look into published properties in protocols. Thanks for the heads up!
@morpheus4564
@morpheus4564 3 жыл бұрын
TDD ? :)
@Eugene.Berezin
@Eugene.Berezin 4 жыл бұрын
Wait, you didn’t stop and re-record the entire video because of 1 typo?! Lol 😂 jk jk. It’s a super dope video tho! I like how you explain mocking!
@Kilo_Loco
@Kilo_Loco 4 жыл бұрын
Lol hell no! Honestly, besides that mess up, I thought this video nailed it
@nyambe
@nyambe 3 жыл бұрын
I am find it a bit hard to see a real advantage of mvvm vs reusable components architecture
@arsars3996
@arsars3996 3 жыл бұрын
learn DI
@Kilo_Loco
@Kilo_Loco 3 жыл бұрын
What do Dinosaur Igloos have to do with any of this?
@williamstorey5024
@williamstorey5024 3 жыл бұрын
how come you didn't declare the view model in the usersview as @observableobject? instead you used state?
Why no RONALDO?! 🤔⚽️
00:28
Celine Dept
Рет қаралды 113 МЛН
Support each other🤝
00:31
ISSEI / いっせい
Рет қаралды 34 МЛН
Арыстанның айқасы, Тәуіржанның шайқасы!
25:51
QosLike / ҚосЛайк / Косылайық
Рет қаралды 639 М.
Калькулятор на SwiftUI / MVVM / Урок 1
41:18
iOS Bulgakov
Рет қаралды 3 М.
MVVM Tutorial for Absolute Beginners with SwiftUI (iOS 2022)
10:36
Why Can't We Make Simple Software? - Peter van Hardenberg
41:34
Handmade Cities
Рет қаралды 124 М.
SwiftUI MVVM Tutorial: Simple Example with ObservableObject
12:43
Logan Koshenka
Рет қаралды 20 М.
Microservices are Technical Debt
31:59
NeetCodeIO
Рет қаралды 673 М.
STOP using MVVM for SwiftUI | Clean iOS Architecture
18:58
Rebeloper - Rebel Developer
Рет қаралды 30 М.
Migrating to Combine
22:51
Kilo Loco
Рет қаралды 19 М.
Dependency Injection, The Best Pattern
13:16
CodeAesthetic
Рет қаралды 894 М.
Why no RONALDO?! 🤔⚽️
00:28
Celine Dept
Рет қаралды 113 МЛН