Тёмный

STOP using MVVM for SwiftUI | Clean iOS Architecture 

Rebeloper - Rebel Developer
Подписаться 26 тыс.
Просмотров 30 тыс.
50% 1

Опубликовано:

 

12 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 103   
@rebeloper
@rebeloper 3 года назад
What is your favourite Design Pattern in SwiftUI?
@AswathNarayanan92
@AswathNarayanan92 3 года назад
Hey, I got the same idea when I started working on our SwiftUI/ Combine project a year ago. However, I left the names as it is. Observed is still the ViewModel, Identifiable is still the Model in our architecture. This combined with a variant of clean architecture for our Combine pipelines has made our codebase so neat and intuitive.
@NattapongU
@NattapongU 2 года назад
TCA
@unchilangoperdido7269
@unchilangoperdido7269 2 года назад
Dont think this pattern has clean ios arch, it's already breaking SRP in the view, the view has to talk to network layer, there's no separation of concerns, nor dependency injection this is not testable.
@artemhrebinik7288
@artemhrebinik7288 Год назад
What about clean Swift + VIP?
@natgenesis5038
@natgenesis5038 5 месяцев назад
MVVM is perfect to me
@Jonauz
@Jonauz 2 года назад
There is no difference from MVVM and what you've described here apart from just putting a different label/name and made such a big claim to "STOP using MVVM". Was expecting at least some challenging arguments and new solutions exclusive for SwiftUI. We us this in our projects.
@rebeloper
@rebeloper 2 года назад
Good point Jonas. I just wanted to present a SwiftUI specific architecture that I use. BTW Do you know the 60-30-10 Rule of Coding? Check it out here: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-0ZH2HmMAD5E.html
@alexeylobankov
@alexeylobankov 2 года назад
Besides the naming and nesting one type into another, how exactly this pattern differs from a regular mvvm?
@rebeloper
@rebeloper 2 года назад
Nothing much. That alone makes it super safe and SwiftUI like. Do you love SwiftUI? Let me tell you the 7 things I HATE about SwiftUI: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-N2i28zxjfvs.html
@jasonelwoodphoto
@jasonelwoodphoto 2 года назад
15 minutes in and I am thinking the same exact thing.
@difengchen6431
@difengchen6431 2 года назад
I wanna ask the same thing 🤣
@moalsamman
@moalsamman 2 года назад
IMO You just renamed ViewModel class in MVVM to Observed
@rebeloper
@rebeloper 2 года назад
Kinda, but there's more to it. BTW are you using keychain to secure your data? Watch this video where I explain how easy it is to use keychain in Swift: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-csssezPchoI.html
@pawelpow
@pawelpow 3 года назад
This is basically MVVM but the Model has to be identifiable and the view model is inside the View
@rebeloper
@rebeloper 3 года назад
That is correct. Being that said IVO is a bit closer to the SwiftUI jargon :) BTW here's a must watch for iOS developers: Clean Code Principles ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-2lD8fjedeis.html
@pawelpow
@pawelpow 3 года назад
@@rebeloper Thank you. By the way, when I saw this video I thought it was a bit silly but now I definitely agree - IVO is much cleaner compared to MVVM, going to use this from now on.
@jlambert12013
@jlambert12013 Год назад
So just Model, View, ViewModel EXCEPT we call it Identifiable, View, Observed. GENIUS.
@rebeloper
@rebeloper Год назад
Correct. More restrictions, much more readable, SwiftUI like :) Till than take a look at my lates video about 30 Xcode Keyboard Shortcuts You NEED to Know: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-CWjHI3vZLSk.html
@imfractured
@imfractured Год назад
He’s just creating flat scopes that will inevitably cause massive memory and scoping issues for redrawing once you have to add more than a single screen to your test app. Would not recommend doing anything similar to this. There’s really no pattern here, and the way he’s managing the view model makes me think he doesn’t even understand why you’d want a view model in the first place or how you’d write tests to cover this monstrosity
@rebeloper
@rebeloper Год назад
Recently I've been using custom property wrappers instead of MVVM :) Did you wonder if will AI replace programmers? Check out my take on it 👇 ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-9NlECBGI-OM.html&ab_channel=Rebeloper-RebelDeveloper
@Antonnel7
@Antonnel7 2 года назад
If you return something that is unstable, like UUID() or an index, this means you get a new object each time you get the object and this will kill reusability and can cause epic memory and layout process usage beside view management issues like transition management and etc.
@rebeloper
@rebeloper 2 года назад
Thanks for the input. 🙀 Check out CoreData in SwiftUI 4: What You Need to Knowru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-L3uLEXFCaVI.html
@paulikhane
@paulikhane 2 года назад
Why I like the concept for it simplicity it may end up creating difficulty for a medium or large project. The layers are tightly coupled so maintaining the code will become a big issues quickly. I always advocate for separating business logic from every other layer/part of your code and business layer should never depend on any concrete implementation of any other part of your code.
@rebeloper
@rebeloper 2 года назад
I couldn't agree more, Paul. BTW Here I talk about The Harsh Reality of Being a Software Engineer 👉 ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-IxweswL5SjI.html
@charleschen2029
@charleschen2029 3 года назад
No offense but i feel like put functions in the views kind of messy to me , I prefer mvvm I’d say
@rebeloper
@rebeloper 3 года назад
I like to have them also in the View and complete/throw with optional errors so I can show the on the View as an Alert :) Of course the logic should definitely be done on the view model. If you enjoyed this video make sure to check out my newest tutorial about iOS15 availability: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-u1SMCxmYMvE.html
@bangonkali
@bangonkali 2 года назад
@@rebeloper is it also okay to have another observed value within the extension that has a cleaner payload of erro? So one can just mutate view depending on the cleaner observed Error?
@vicyt007
@vicyt007 2 года назад
A function may be in the View if it just concerns the User Interface layer.
@cristianf98
@cristianf98 9 месяцев назад
This doesn't changes anything to MVVM, is the same pattern with different naming conventions. Observable could just be @State, and profile doesn't need to conform to Identifiable if you're not going to use that conformances for something, like display the fetched entities in it in a list, which is not the case since your fetch fetches a single profile.
@rebeloper
@rebeloper 9 месяцев назад
It makes it more robust :) Next watch Xcode Meets AI: Take Your App Development to New Heights 👇 ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-xwcPYSezBxA.html&ab_channel=Rebeloper-RebelDeveloper
@WilfClegg
@WilfClegg 2 года назад
Thank you for this tutorial. It is the cleanest and easiest to understand. I've viewed many MVVM tutorials, and they are usually convoluted by using components that detract from the basic inter-file communication. This makes it more overwhelming to visualize. Your example is straight and to the point, with no distracting "extras". I also really like your teaching style, and look forward to following more of your tutorials. Thanks again!
@rebeloper
@rebeloper 2 года назад
Thank you for the kind words. Glad you like my teaching style. I also do 1:1 mentoring: rebeloper.com/mentoring BTW Find out How to Create Custom a Framework in Swift within minutes 👉 ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-2k4mMdLfIKY.html
@krystiansolarz1596
@krystiansolarz1596 3 года назад
Hmm interesting : ) what about navigation?
@rebeloper
@rebeloper 3 года назад
I cover navigation here: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-yLLzD4Nm1Rk.html
@bobweiram6321
@bobweiram6321 2 года назад
Why did you use an optional value instead of a default parameter value?
@rebeloper
@rebeloper 2 года назад
It's just personal preference :) both work fine. If you liked this one you will love my latest video on Timers: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-oo-sW_Ds968.html
@ugommirikwe
@ugommirikwe Год назад
I was just wondering the same thing 🤷 He just complicated a well known and simpler way of overloading methods/initialisers 🤦
@m4r70x
@m4r70x 2 года назад
Hello, thanks for the explanation, I applied it in a demo that I am making to practice SwiftUI, but I have a doubt, Could you give me an example of where I should declare an EnviromentObject? would it be inside the View or inside the Observed class?
@rebeloper
@rebeloper 2 года назад
Let me explain in detail in a mentoring session rebeloper.com/mentoring Best iOS Development Tools - Summer Sale 👇 ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-HzGgXjyF8ak.html
@ScaleCodingSkills
@ScaleCodingSkills 3 года назад
which Xcode theme you are using, it looks decent and clean.
@rebeloper
@rebeloper 3 года назад
It's detailed in this video: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-fUk9hLLPvqo.html
@nat.serrano
@nat.serrano Год назад
can you do a video about TCA architecture>?
@rebeloper
@rebeloper Год назад
Thanks for the suggestion. Will consider it. Next watch Mastering App Distribution With TestFlight And App Store Connect 👇 ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-GyD6t0GnWp0.html&ab_channel=Rebeloper-RebelDeveloper
@indomitabletr1834
@indomitabletr1834 2 года назад
i heard is first time, from you, thank you to make us noticed
@rebeloper
@rebeloper 2 года назад
Glad you like it. BTW Becoming A Front End Developer Takes Time 👉 ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-Hx2tE19jYn8.html
@crimsondragon95
@crimsondragon95 3 года назад
HI Rebel! Im new-ish in iOS dev, curious to know use cases for this pattern? Should I use this for my job or personal project? I do like how this reduces the amount of models (or view models) to create especially if the Model or ViewModel is for that specific View only while at the same time easier to set up in the beginning. This almost feels like MVVM, with the difference of naming and access. Is this still easy to test?
@rebeloper
@rebeloper 3 года назад
You are correct about IVO. I would use this in a Team if the team would agree to use it, considered the upsides of IVO over MVVM. Yes it is testable
@federicotorres6227
@federicotorres6227 2 года назад
How would you share an observed object between several views?
@rebeloper
@rebeloper 2 года назад
Either use @environmentObject or move it into the Views with @ObservedObject. I can show it to you in a mentoring session: rebeloper.com/mentoring BTW check out this New MUST HAVE SwiftUI View 👉 ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-qJNy-u5gbq8.html
@jonathansack2433
@jonathansack2433 Год назад
Just curious: with this approach, how do you handle the case where one observed resource needs to be shared and observed by multiple views ?
@rebeloper
@rebeloper Год назад
For that case I would set up the shared ObservableObject as an environment object. Next Unlock the Power of Core Data Versioning! 👇 ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-RDtLWWos3cA.html&ab_channel=Rebeloper-RebelDeveloper
@aelamw
@aelamw 2 года назад
the init func is really a bad practice, why not give Date() instead of nil as the default value
@rebeloper
@rebeloper 2 года назад
That approach is also valid. Find Out How Senior Programmers ACTUALLY Write Code 👉 ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-3PlcehlBlS4.html
@omerbyrk
@omerbyrk Год назад
Well, I learnt how mvvm works thanks to you.
@rebeloper
@rebeloper Год назад
You have to learn the pros and cons so you can decide if and how you're going to use it. Did you wonder if will AI replace programmers? Check out my take on it 👇 ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-9NlECBGI-OM.html&ab_channel=Rebeloper-RebelDeveloper
@grimesoutdoors
@grimesoutdoors 2 года назад
Love this refinement on the MVVM pattern. I’ve implemented similar patterns in Angular2 in the web side. Nice walkthrough Alex!
@rebeloper
@rebeloper Год назад
Cool, thanks! 🎉 Just updated StoreKitPro 👉 ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE--gkvRIVEZss.html
@manueldefreitas1199
@manueldefreitas1199 Год назад
What about when using concurrency (async/await)? How does that work with IVO?
@rebeloper
@rebeloper Год назад
Works exactly the same. No changes are required. BTW are you using NavigationView or NavigationStack in your SwiftUI projects? STOP using Navigation Stack in SwiftUI! Use THIS instead... 👇 ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-LR0uK5Mc2CM.html
@DardanAirlines
@DardanAirlines Год назад
You seem to be promoting MVVM, even though you say otherwise. One of the hallmarks of MVVM is testability, and I find it odd that the folks taking the time to write articles about why MVVM doesn't work with SwiftUI, conveniently leave out how one might otherwise unit test their code.
@rebeloper
@rebeloper Год назад
You're perfectly right. My suggestion is MVVM just pinpointed for SwiftUI specifically. Also yes, testing is great with MVVM. Next: Make Sure You Always Get the Best Error Alerts! 👇 ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-VWgZ99FTuBU.html
@azamsharp
@azamsharp 2 года назад
I agree! View in SwiftUI is the View Model.
@rebeloper
@rebeloper 2 года назад
In some cases you do need a VM. But mostly it's just the View. BTW check out these 8 Mind-Blowing Websites You Probably Didn't Know Existed 👉 ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-BGJgBjnCSM0.html
@fulviofagnani8395
@fulviofagnani8395 Год назад
Very interesting. Just wondering how this would simplify getting automatic coredata database updates that @FetchRequest offers Thanks
@rebeloper
@rebeloper Год назад
I do not use MVVM at all with CoreData. The property wrappers provided by SwiftUI are more than enough, so I use only the views. SwiftData is even easier. BTW have you seen Firebase Login in SwiftUI: Step by Step Masterclass 👇 ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-9lRWau51lGw.html&ab_channel=Rebeloper-RebelDeveloper
@fulviofagnani8395
@fulviofagnani8395 Год назад
@@rebeloper I understand thanks! And can’t wait for SwiftData to be fully ready for use!
@rebeloper
@rebeloper Год назад
Yeah, check the video about the beta here: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-0CQHc9Wz25Q.htmlsi=W3kvc0wtNji1asUz
@olegkovtun5011
@olegkovtun5011 2 года назад
Looks like MVVM with a different naming ) But anyway, thank you for the video )
@rebeloper
@rebeloper 2 года назад
Yes, you are right. Made it really "tight", SwiftUI specific. BTW here are 6 things I wish I knew about SwiftUI when I started 👇 ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-EZz9NL4H0Ug.html
@thomaswilson1111
@thomaswilson1111 2 года назад
Going to try to use IVO for my second app. Wish me luck!
@rebeloper
@rebeloper 2 года назад
You can do it, Thomas! Let me know if you have any issues. BTW are you a PRO developer? TRY THIS: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-fw8NIizbYMU.html
@DavidNitzscheBell
@DavidNitzscheBell 2 года назад
This looks very interesting. Will try it out. You *almost* addressed something which I've been struggling with, so I'll ask you here..... Hope you don't mind. Many apps have a sign-up/sign-in ability and then a User Profile page that can be filled in. But....what if the properties in the User struct are optional? Mine has `name` and `email` as Strings, but then I have 5-10 other properties which are all optional: dateOfBirth: Date?, gender (an optional Enum), heightInCM (optional Int), and more. Following Peter Friese's Books app, I like the idea of having one view to display the User Profile and clicking "Edit" to update the User's properties. But, if the user edits their profile but only adds *one* value, say their birthdate, and doesn't change the other values, how will they maintain their nil values? I can fake it for anything that uses a TextField, but for Pickers, Toggles, etc....there doesn't seem to be a useful, non-clunky solution. If you have any thoughts, ideas, suggestions - even other places I could ask that are not as judgemental as SO - I'd be happy for any pointers. Thanks again for you interesting video.
@rebeloper
@rebeloper 2 года назад
Take a look at BetterCodable on GitHub. It addresses the exact issue you are having. If you need me to explain I'm available here: rebeloper.com/mentoring BTW do you want to know why 95% of self-taught developers fail? Find out why here: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-pZaot8RA84g.html
@MrMassmaker
@MrMassmaker 2 года назад
how about the memory cycle in Observed's completion ?)
@rebeloper
@rebeloper 2 года назад
Could you elaborate? Find Out How Senior Programmers ACTUALLY Write Code 👉 ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-3PlcehlBlS4.html
@leonidstechlearning2451
@leonidstechlearning2451 2 года назад
Can you show us how to write Unit Tests with this pattern?
@rebeloper
@rebeloper 2 года назад
Sorry, SwiftUI is not going well with Test... for now. BTW Becoming A Front End Developer Takes Time 👉 ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-Hx2tE19jYn8.html
@42ALR42
@42ALR42 Год назад
Basically he is not using protocols at all, difficult to test. He is basically applying basically MVVM with another name, and not making any protocols that conform the VM, thus his code is difficult to test.
@ugommirikwe
@ugommirikwe Год назад
I think the author’s efforts in making tutorial videos are helpful for the most part, but going by this video he is completely leading new and inexperienced SwiftUI developers down a rabbit hole filled with frustrations. There’s absolutely no advantage to doing this “pattern” over MVVM. One of the main reasons for these UI patterns is to make it easy to implement automated tests on the code base, but he didn’t even demonstrate how this “pattern” of his makes it easier to test. Meanwhile, why do you use optional/nil parameters for the “UserProfile” struct initializer instead of just using a more idiomatic default initializer/method parameter values? All in all, thank you for making this video but I advise other watchers to be more circumspect with what they “learn” from it.
@rebeloper
@rebeloper Год назад
Thanks for the feedback. I too matured since :) Did you wonder if will AI replace programmers? Check out my take on it 👇 ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-9NlECBGI-OM.html&ab_channel=Rebeloper-RebelDeveloper
@gnoyl
@gnoyl Год назад
It is really distracting to watch you look at keyboard every time you type something. Stoping in middle to check what you write and then keep writing. How many years of experience do you have in order not to be able to type without looking at your keyboard?
@rebeloper
@rebeloper Год назад
Programming is not about typing ;P Let me show you a Progress Button in SwiftUI 👇 ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-kF8Qk28-FFU.html
@maximg6474
@maximg6474 2 года назад
How?! How did you change -> to an arrow?
@rebeloper
@rebeloper 2 года назад
It's right here: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-fUk9hLLPvqo.html BTW here are 18 Commands That WILL Change The Way You Use Terminal Forever 👉 ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-C90lCH-_EBU.html
@AntiSmithhh
@AntiSmithhh 2 года назад
looks like renamed MVVM with outdated GCD
@rebeloper
@rebeloper 2 года назад
Kinda. 🤑 Do you want to make MONEY with your iOS apps? Learn how to here: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-37qEN4flc3I.html
@andybezaire
@andybezaire 2 года назад
Why does *struct Profile* have to be *Identifiable* ?
@rebeloper
@rebeloper 2 года назад
They do not HAVE to be but it's a good idea. Maybe you're going to use them inside a List... BTW do you want to know why 95% of self-taught developers fail? Find out why here: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-pZaot8RA84g.html
@vicyt007
@vicyt007 2 года назад
If you use the profiles in List or ForEach, the profile needs to be Identifiable.
@acjazz01
@acjazz01 2 года назад
It might work for small projects. But for medium and big projects, with thousands of business rules, it will just fail miserably. MVVM remains the best choice for any iOS project, specially big ones.
@rebeloper
@rebeloper 2 года назад
Thanks for you input. Do you have experience with medium/big projects? BTW let's create a Sudoku Solver In Swift 👉 ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-u7A6mdTq3eU.html
@cristianf98
@cristianf98 Год назад
Did we watch the same video? This is literally MVVM...
@jonnyjones6119
@jonnyjones6119 Год назад
Came here for the comments. Another clickbaity video. MVVM all the way. Don’t respond with a link to another video like you do with all your other replies thanks
@rebeloper
@rebeloper Год назад
Did you find the comments helpful?
@KK-pq6lu
@KK-pq6lu 3 года назад
Can the identifiable be a Core Data Entity?
@rebeloper
@rebeloper 3 года назад
Sure! Make sure that you create an id property that you can manually use.
@kekearif
@kekearif Год назад
This is just MVVM renamed
@rebeloper
@rebeloper Год назад
MVVM refrained for SwiftUI, I would say :) Next: Make Sure You Always Get the Best Error Alerts! 👇 ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-VWgZ99FTuBU.html
@user-wp2hn9pg1n
@user-wp2hn9pg1n 2 года назад
As my opinion this approach is bad shit. We can use only VM (veiw, model) for SwiftUI app.
@rebeloper
@rebeloper 2 года назад
The VM approach is also viable for SwiftUI apps, but Apple recommends MVVM as a basis. Find Out How Senior Programmers ACTUALLY Write Code 👉 ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-3PlcehlBlS4.html
@yarn-rdgz
@yarn-rdgz 2 года назад
Please stop using the clean architecture label in this videos. This is just MVVM with makeup
@rebeloper
@rebeloper 2 года назад
Why is that not clean 🤔
Далее
А на каком языке ты ДУМАЕШЬ?
00:57
To mahh too🫰🍅 #abirzkitchen #tomato
01:00
Просмотров 5 млн
DC iOS: SwiftUI Architecture and Best Practices
1:15:19
Why I don't do MVVM anymore
10:56
Просмотров 7 тыс.
Understand Clean Architecture in 7 Minutes
7:02
Просмотров 102 тыс.
MVVM is BAD for SwiftUI - Use MVC Instead! (Yes, MVC)
13:28
Data Flow in a SwiftUI App
33:15
Просмотров 53 тыс.
STOP Using MVVM with SwiftUI
18:30
Просмотров 16 тыс.