MVVM is BAD for SwiftUI - Use MVC Instead! (Yes, MVC)

  Рет қаралды 4,653

Rebeloper - Rebel Developer

Rebeloper - Rebel Developer

Күн бұрын

Пікірлер: 31
@rebeloper
@rebeloper Жыл бұрын
Stop using Spacer in SwiftUI (and what to use instead) 👉 kzbin.info/www/bejne/iWfFppmEn66nm7M&ab_channel=Rebeloper-RebelDeveloper
@imamad
@imamad Жыл бұрын
Thanks for the video. However, you only renamed VM to Controller and moved it in root view. The only point of this video was only a renaming!
@rebeloper
@rebeloper Жыл бұрын
Not really. I also touch on some important points about view models. Next watch Mastering SwiftUI's Night Mode: Unlock Next-Level App Design 👇 kzbin.info/www/bejne/h56UhJlmpLSqnKs&ab_channel=Rebeloper-RebelDeveloper
@smithshaw1151
@smithshaw1151 7 ай бұрын
@@rebeloper Don't get it. What has night mode got to do with MVVM vs MV+C
@sajjadsarkoobi
@sajjadsarkoobi Жыл бұрын
Thanks for your videos. There is a big But here. If you define a Controller (ViewModel) as an Environment object, it will always exist in memory. while when you are creating views and mentioning a ViewModel as @StateObject (you add @State, which is wrong for defining a ViewModel or controllers), it will be deinitialized when the view is destroyed. So for enterprise projects, it is a very bad way to create Controllers(ViewModels) as an environment object.
@Andrew-7324
@Andrew-7324 Жыл бұрын
Apple deprecated @StateObject
@sajjadsarkoobi
@sajjadsarkoobi Жыл бұрын
@@Andrew-7324 Take a look at apple documentation for @StateObject, and also used cases and samples. It is not deprecated.
@rebeloper
@rebeloper Жыл бұрын
I am using Xcode 15 therefore @StateObject is now @State I recommend using a controller only when you want to share resources between views. It's the cleanest way of doing it. If the data is tied to a view I suggest ( not using a view model) using @State on the view only. Next watch Mastering SwiftUI's Night Mode: Unlock Next-Level App Design 👇 kzbin.info/www/bejne/h56UhJlmpLSqnKs&ab_channel=Rebeloper-RebelDeveloper
@sajjadsarkoobi
@sajjadsarkoobi Жыл бұрын
@@rebeloper Apple documentation: If you need to store a reference type, like an instance of a class, use a StateObject instead.
@Spacer-l3j
@Spacer-l3j 5 ай бұрын
@@sajjadsarkoobi @StateObject has been replaced by @State now
@MaccabeeCaptain
@MaccabeeCaptain Жыл бұрын
so if UserController was renamed UserViewModel how is that any different than MVVM?
@yourbestsail
@yourbestsail Жыл бұрын
I think the only difference is not making it fileprivate strictly bounded to the view, but available everywhere. I do not see any other difference apart from the use of the Environment. Nevertheless I think that in more complex cases is necessary that a View has its specific ViewModel.
@MaccabeeCaptain
@MaccabeeCaptain Жыл бұрын
@@yourbestsail just find it a bit amusing considering the clickbait title I guess..
@yourbestsail
@yourbestsail Жыл бұрын
@@MaccabeeCaptainActually I did not understand either what’s the real big deal with this. It looks to me that this is not even a general architectural pattern like MVVM. But it may just be because I am not such a super expert…
@rebeloper
@rebeloper Жыл бұрын
View models should be used on views only. If you need to share data between views use a Controller. Next watch Mastering SwiftUI's Night Mode: Unlock Next-Level App Design 👇 kzbin.info/www/bejne/h56UhJlmpLSqnKs&ab_channel=Rebeloper-RebelDeveloper
@rebeloper
@rebeloper Жыл бұрын
Yes, in complex cases.
@Soleusgaming
@Soleusgaming Жыл бұрын
I think people are already using mvc like when passing data through screens we initialise in the main file and pass it as environment .
@rebeloper
@rebeloper Жыл бұрын
Agreed. Next watch Mastering SwiftUI's Night Mode: Unlock Next-Level App Design 👇 kzbin.info/www/bejne/h56UhJlmpLSqnKs&ab_channel=Rebeloper-RebelDeveloper
@casadogaspar
@casadogaspar Жыл бұрын
Correct me if I'm wrong, but it's an easier way to Composition Root? I do it in UIKit creating factories in the AppDelegate, it's the same effect?
@rebeloper
@rebeloper Жыл бұрын
Sorry, I don't really understand your question. Next watch Mastering SwiftUI's Night Mode: Unlock Next-Level App Design 👇 kzbin.info/www/bejne/h56UhJlmpLSqnKs&ab_channel=Rebeloper-RebelDeveloper
@jcpazos65
@jcpazos65 Жыл бұрын
Hi, like you explanation, sure you are going to receive a lot of comments regarding the importance of MVVM because for large projects, and stuff like that. At the end I really support your comments regarding that no problem in put Business logic in the View, because at the end the MMVM file it has to be related to the view so not difference. You approach to use MVC is great.
@rebeloper
@rebeloper Жыл бұрын
Couldn't have said it better myself. The cleaner the architecture, the better. MVVM adds too much cluttter. Next watch Mastering SwiftUI's Night Mode: Unlock Next-Level App Design 👇 kzbin.info/www/bejne/h56UhJlmpLSqnKs&ab_channel=Rebeloper-RebelDeveloper
@natgenesis5038
@natgenesis5038 9 ай бұрын
I totally disagree
@rebeloper
@rebeloper 9 ай бұрын
Why is that? Can you explain?
@rodionov_av
@rodionov_av Жыл бұрын
It's MV architecture. NOT MVC!
@rebeloper
@rebeloper Жыл бұрын
While some views can get away without the controller, there will be at leas one controller in your app, therefor MVC it is :) Next watch Mastering SwiftUI's Night Mode: Unlock Next-Level App Design 👇 kzbin.info/www/bejne/h56UhJlmpLSqnKs&ab_channel=Rebeloper-RebelDeveloper
@tenminutetokyo2643
@tenminutetokyo2643 9 ай бұрын
MVVM is garbage
@rebeloper
@rebeloper 8 ай бұрын
In most complex cases it is. Next watch SwiftUI Navigation Made Easy: Harnessing the Magic of Enums 👇 kzbin.info/www/bejne/mqCXpo14jbVpmMU&ab_channel=Rebeloper-RebelDeveloper
Why You Should Use The SwiftUI Coordinator Pattern
18:45
Rebeloper - Rebel Developer
Рет қаралды 15 М.
Why I don't do MVVM anymore
10:56
Flo writes Code
Рет қаралды 7 М.
My MEAN sister annoys me! 😡 Use this gadget #hack
00:24
JOON
Рет қаралды 1,5 МЛН
СОБАКА ВЕРНУЛА ТАБАЛАПКИ😱#shorts
00:25
INNA SERG
Рет қаралды 2,6 МЛН
Which One Is the Best? - Observable vs. ObservableObject
10:54
Rebeloper - Rebel Developer
Рет қаралды 1,7 М.
STOP Using MVVM with SwiftUI
18:30
azamsharp
Рет қаралды 17 М.
How to use Model View Controller MVC in iOS (Swift 2020)
16:34
iOS Academy
Рет қаралды 25 М.
Infinite Carousel in SwiftUI! (Easier Than You Think)
13:27
Rebeloper - Rebel Developer
Рет қаралды 1,9 М.
Uncover the Simplicity of SwiftData: Replace CoreData in Seconds!
35:14
Rebeloper - Rebel Developer
Рет қаралды 4,8 М.
Dependency Injection in SwiftUI, the Best Pattern
14:55
Rebeloper - Rebel Developer
Рет қаралды 4,4 М.
Mastering SwiftUI's Night Mode: Unlock Next-Level App Design
12:35
Rebeloper - Rebel Developer
Рет қаралды 517
Unlock Stunning Navigation Animations in SwiftUI! 🚀 Step-by-Step Guide!
11:49
Rebeloper - Rebel Developer
Рет қаралды 1,2 М.
My MEAN sister annoys me! 😡 Use this gadget #hack
00:24
JOON
Рет қаралды 1,5 МЛН