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

Комментарии • 33

  • @v_pradeilles
    @v_pradeilles  2 года назад +10

    Did you find this explanation useful? Are you planning on using MVVM in your apps? Let me know in the comments 🚀

  • @hosseindastan6221
    @hosseindastan6221 2 года назад +8

    it would be good to see also combine version.

  • @idanboadana3611
    @idanboadana3611 2 года назад +3

    Great video! I actually would love to see this implemented with Combine, and more Combine videos would be amazing :)

  • @TheLeonardofs89
    @TheLeonardofs89 2 года назад +4

    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!

  • @pkc456
    @pkc456 2 года назад +6

    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?

    • @v_pradeilles
      @v_pradeilles  2 года назад +2

      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.

  • @Iwasee
    @Iwasee Год назад

    Thanks a lot ! I really enjoyed your example, small amount of code is so much more better for understanding !

  • @40tutur
    @40tutur 2 года назад +1

    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 ;)

  • @rohitdhawan02
    @rohitdhawan02 2 года назад

    Yes Vincent, though already using MVVM.

  • @robinandthedog
    @robinandthedog 2 года назад +1

    Very well explained, merci beaucoup!

  • @jebamoses3209
    @jebamoses3209 2 года назад +1

    Good Explanation👍🏻

  • @garyash7607
    @garyash7607 2 года назад

    Good video. Myself, I'd consider formatting to a view responsibility

  • @sdmf195
    @sdmf195 2 года назад +1

    Thank you so much :)

  • @rev_kous9275
    @rev_kous9275 2 года назад +2

    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.

  • @cozybazaar
    @cozybazaar 2 года назад

    Please do one about VIPER too 😍🙏🏻

  • @developerios6096
    @developerios6096 2 года назад

    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" ?

  • @junaidkamoka4059
    @junaidkamoka4059 2 года назад +1

    Thanks

  • @Kel_jellyfish
    @Kel_jellyfish 2 года назад

    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.

    • @v_pradeilles
      @v_pradeilles  2 года назад +1

      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.

  • @idembele
    @idembele 2 года назад

    Je ne comprends toujours pas. Je pense que je vais la regarder encore.. et encore.. et et encore ta vidéo... Merci Vincent

    • @idembele
      @idembele 2 года назад

      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?

  • @JLCodes
    @JLCodes 2 года назад

    What is the purpose of extending your ViewModel to NSObject?

    • @v_pradeilles
      @v_pradeilles  2 года назад

      You don't really need it to conform to NSObject, I did it more by force of habit than anything else.

  • @laurentk2033
    @laurentk2033 2 года назад

    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 :)

    • @v_pradeilles
      @v_pradeilles  2 года назад +2

      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

  • @yogeshdeshmukh1642
    @yogeshdeshmukh1642 2 года назад

    great

  • @Dragonrojo2555
    @Dragonrojo2555 2 года назад +1

    Why the ViewModel is an Nsobject?

    • @v_pradeilles
      @v_pradeilles  2 года назад +1

      Force of habit, I don’t think it’s actually necessary

  • @vm3172
    @vm3172 Год назад

    ALO BILL GATES TAO VENDENDO DIPLOMA EM SETE LAGOAS FORMEI SEM SABER INGLES E NEM SEI PROGRAMAR HAUAUHUHAUHAUH

  • @zivzalzstein3776
    @zivzalzstein3776 2 года назад

    why 'viewModel.updateUI` is in the viewDidLoad and not viewWillAppear?

    • @v_pradeilles
      @v_pradeilles  2 года назад

      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.