How to implement the MVVM architecture in Swift!
HTML-код
- Опубликовано: 8 сен 2024
- #iOS #swift #softwaredeveloper #iosdeveloper
Thank you for watching this video 🙌
Get the code 👉 bit.ly/3siaUnT
I use Ecamm Live to record my videos, check it out 👉 bit.ly/3n9CClf
(affiliate link)
➜ Leave a tip: www.buymeacoff...
➜ Website: www.swiftwithv...
➜ Twitter: / v_pradeilles
➜ GitHub: github.com/vin...
➜ LinkedIn: / vincentpradeilles
Did you find this explanation useful? Are you planning on using MVVM in your apps? Let me know in the comments 🚀
it would be good to see also combine version.
Request noted 📝
Great video! I actually would love to see this implemented with Combine, and more Combine videos would be amazing :)
This is very informative! It actually helped me in an interview!!! As a request, I would love to see some S.O.L.I.D. principles in Swift codings, if possible! Thank you so much and keep on with your great work!
Good video, some questions for you:
1. Why ViewModel inherit form NSObject?
2. Don't we need to use the main thread to display data?
Good questions!
1. Force of habit. I don’t think you actually have to.
2. Very good point, I kept that part out, because it was a bit out of topic, but you definitely want to make sure that the UI is updated only on the main thread.
Thanks a lot ! I really enjoyed your example, small amount of code is so much more better for understanding !
Thanks for the video !
Very simple, popular and useful pattern ! But i prefer to use MVI pattern, unidirectional data flow, single source of truth for the UI state ! For me it's a very interesting good evolution of MVVM pattern :)
That's just my opinion of course ;)
Yes Vincent, though already using MVVM.
Very well explained, merci beaucoup!
Good Explanation👍🏻
Good video. Myself, I'd consider formatting to a view responsibility
Thank you so much :)
Pourras-tu stp faire une vidéo avec la variante du MVVM, qu'est MVVM-C (Coordinator) ? Je trouve que c'est très important de savoir implémenter l'architecture MVVM avec les Coordinators.
Je note l'idée !
Please do one about VIPER too 😍🙏🏻
Hi vincent, easy to understand and interesting. A good old imperative approach, but i was wondering if we could implement a closure(in fetchData) to let us know when fetchData got the actual data. Tipically, we want our UI to be refreshed as soon as the new data is available. Would this solution be "too much reactive" ?
Thanks
I want to use my data for table view but outside the closure the array return nil. It's my first step with the MVVM pattern.
For this use case, MVVM with closures can be indeed a bit clunky. You basically have two approaches:
1. the ViewModel stores the latest value of the array of data in a property (ideally with a public getter and a private setter).
2. you go for the MVP pattern, which makes it a bit easier to work with table views.
Je ne comprends toujours pas. Je pense que je vais la regarder encore.. et encore.. et et encore ta vidéo... Merci Vincent
je pense que c'est la closure de updateUI m'embrouille :D. Le newData (dans viewController.updateUI) c'est une sorte de property Observer? Est ce une sorte de didSet?
What is the purpose of extending your ViewModel to NSObject?
You don't really need it to conform to NSObject, I did it more by force of habit than anything else.
Hello Vincent, I'm new in iOS, for the moment I've been learning both UIKit and SwiftUI but wich should I learn more in depth? And if the answer is both wich one at first?
Greets from Belgium :)
Let me redirect you to Paul Hudson's website, because he's written a great article on this very topic 👉 www.hackingwithswift.com/quick-start/swiftui/answering-the-big-question-should-you-learn-swiftui-uikit-or-both
great
Why the ViewModel is an Nsobject?
Force of habit, I don’t think it’s actually necessary
ALO BILL GATES TAO VENDENDO DIPLOMA EM SETE LAGOAS FORMEI SEM SABER INGLES E NEM SEI PROGRAMAR HAUAUHUHAUHAUH
why 'viewModel.updateUI` is in the viewDidLoad and not viewWillAppear?
Here the reason is that the closure will be the same for the entire lifetime of the view controller.
You could also set the closure in viewWillAppear and set it to nil in viewWillDisappear, if you don’t want the controller to be updated when it’s out of the screen.