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

  Переглядів 3,574

Rebeloper - Rebel Developer

Rebeloper - Rebel Developer

День тому

MVVM is BAD for SwiftUI - Use MVC Instead! (Yes, MVC)
Mentoring 👉 rebeloper.com/mentoring
In this video, I'm going to convince you that using MVVM is a bad idea for SwiftUI - and that you should instead use MVC!
MVVM is a popular design pattern for building UIs with Swift, but in this video I'll show you why MVC is a better solution for SwiftUI. I'll cover the benefits of using MVC for your SwiftUI applications, as well as some best practices for using MVC in your SwiftUI projects. So if you're looking for a better way to build your SwiftUI applications, then you should watch this video!
00:00 INTRO
00:20 MVC: MODEL - VIEW - CONTROLLER
01:01 WHAT IS MVVM
02:45 MENTORING
03:20 MODEL AND VIEWMODEL IN MVVM
07:09 WHY MVVM IS BAD FOR SWIFTUI
08:29 MVC IN SWIFTUI
12:55 WHERE TO GO FROM HERE
→ PLAYLIST:
SwiftUI Best Practices 👉 • MVVM is BAD for SwiftU...
DO YOU WANT TO ME TO WORK ON YOUR PROJECT?
HIRE ME → rebeloper.com/hire-us/
TOOLS I RECOMMEND:
→ rebeloper.com/tools
__________
Get in touch:
→ support@rebeloper.com
SUBSCRIBE to weekly tips & tutorials for building iOS apps!
→ ukposts.info?su...
GitHub: github.com/rebeloper/
Hire me: rebeloper.com/hire-us/
LinkedIn: / rebeloper
My Blog: rebeloper.com/blog
Follow me on Instagram: / rebeloper
Twitter: / rebeloper
______
#rebeloper

КОМЕНТАРІ: 27
@rebeloper
@rebeloper 8 місяців тому
Stop using Spacer in SwiftUI (and what to use instead) 👉 ukposts.info/have/v-deo/i2aTqZyFoX-lxoU.html&ab_channel=Rebeloper-RebelDeveloper
@imamad
@imamad 7 місяців тому
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 7 місяців тому
Not really. I also touch on some important points about view models. Next watch Mastering SwiftUI's Night Mode: Unlock Next-Level App Design 👇 ukposts.info/have/v-deo/iZ1ih5xnpoWox30.html&ab_channel=Rebeloper-RebelDeveloper
@smithshaw1151
@smithshaw1151 Місяць тому
@@rebeloper Don't get it. What has night mode got to do with MVVM vs MV+C
@casadogaspar
@casadogaspar 8 місяців тому
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 7 місяців тому
Sorry, I don't really understand your question. Next watch Mastering SwiftUI's Night Mode: Unlock Next-Level App Design 👇 ukposts.info/have/v-deo/iZ1ih5xnpoWox30.html&ab_channel=Rebeloper-RebelDeveloper
@MaccabeeCaptain
@MaccabeeCaptain 8 місяців тому
so if UserController was renamed UserViewModel how is that any different than MVVM?
@yourbestsail
@yourbestsail 8 місяців тому
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 7 місяців тому
@@yourbestsail just find it a bit amusing considering the clickbait title I guess..
@yourbestsail
@yourbestsail 7 місяців тому
@@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 7 місяців тому
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 👇 ukposts.info/have/v-deo/iZ1ih5xnpoWox30.html&ab_channel=Rebeloper-RebelDeveloper
@rebeloper
@rebeloper 7 місяців тому
Yes, in complex cases.
@sajjadsarkoobi
@sajjadsarkoobi 7 місяців тому
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-ua772
@Andrew-ua772 7 місяців тому
Apple deprecated @StateObject
@sajjadsarkoobi
@sajjadsarkoobi 7 місяців тому
@@Andrew-ua772 Take a look at apple documentation for @StateObject, and also used cases and samples. It is not deprecated.
@rebeloper
@rebeloper 7 місяців тому
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 👇 ukposts.info/have/v-deo/iZ1ih5xnpoWox30.html&ab_channel=Rebeloper-RebelDeveloper
@sajjadsarkoobi
@sajjadsarkoobi 7 місяців тому
@@rebeloper Apple documentation: If you need to store a reference type, like an instance of a class, use a StateObject instead.
@Soleusgaming
@Soleusgaming 8 місяців тому
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 7 місяців тому
Agreed. Next watch Mastering SwiftUI's Night Mode: Unlock Next-Level App Design 👇 ukposts.info/have/v-deo/iZ1ih5xnpoWox30.html&ab_channel=Rebeloper-RebelDeveloper
@jcpazos65
@jcpazos65 8 місяців тому
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 7 місяців тому
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 👇 ukposts.info/have/v-deo/iZ1ih5xnpoWox30.html&ab_channel=Rebeloper-RebelDeveloper
@user-jh6ch4qo8x
@user-jh6ch4qo8x 7 місяців тому
It's MV architecture. NOT MVC!
@rebeloper
@rebeloper 7 місяців тому
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 👇 ukposts.info/have/v-deo/iZ1ih5xnpoWox30.html&ab_channel=Rebeloper-RebelDeveloper
@natgenesis5038
@natgenesis5038 3 місяці тому
I totally disagree
@rebeloper
@rebeloper 3 місяці тому
Why is that? Can you explain?
@tenminutetokyo2643
@tenminutetokyo2643 2 місяці тому
MVVM is garbage
@rebeloper
@rebeloper 2 місяці тому
In most complex cases it is. Next watch SwiftUI Navigation Made Easy: Harnessing the Magic of Enums 👇 ukposts.info/have/v-deo/nJ9lqZB5j4Znw5c.html&ab_channel=Rebeloper-RebelDeveloper
iOS Dev 33: MVC Design Pattern Explained with Example | Swift 5, XCode 13
27:42
Why I don't do MVVM anymore
10:56
Flo writes Code
Переглядів 6 тис.
Дурнєв дивиться сторіс ZОМБІ #47
53:48
Aleksey Durnev
Переглядів 556 тис.
"Поховали поруч": у Луцьку попрощались із ДВОМА Героями 🕯🥀 #герої #втрати
00:15
Телеканал Конкурент TV - новини Луцька та Волині
Переглядів 303 тис.
QRCodes in SwiftUI: The Ultimate Tutorial
15:00
Rebeloper - Rebel Developer
Переглядів 1,3 тис.
How to use Model View Controller MVC in iOS (Swift 2020)
16:34
iOS Academy
Переглядів 24 тис.
Every CSS Animation property
9:26
chunkydotdev
Переглядів 40 тис.
STOP using NavigationStack in SwiftUI - Navigation Coordinator is BETTER
28:40
Rebeloper - Rebel Developer
Переглядів 1,1 тис.
Fast & Easy Paywalls with RevenueCat
33:39
Sean Allen
Переглядів 7 тис.
Which Software Architecture Should You Use: MVC, MVP, or MVVM?
24:27
ArjanCodes
Переглядів 103 тис.
ViewModels & Configuration Changes - Android Basics 2023
18:46
Philipp Lackner
Переглядів 91 тис.
New SwiftUI Data Flow with Observation - iOS 17
8:30
iOS Academy
Переглядів 6 тис.
SwiftUI Coordinator Pattern: Everything You Need to Know
37:21
Rebeloper - Rebel Developer
Переглядів 1,1 тис.
Samsung or iPhone
0:19
rishton_vines😇
Переглядів 2,6 млн
The PA042 SAMSUNG S24 Ultra phone cage turns your phone into a pro camera!
0:24
iPhone - телефон для нищебродов?!
0:53
ÉЖИ АКСЁНОВ
Переглядів 3,7 млн
Распаковка айфона под водой!💦(🎥: @saken_kagarov on IG)
0:20
Взрывная История
Переглядів 11 млн