iOS Dev 34: MVVM Design Pattern Explained with Example | Swift 5, XCode 13

Поделиться
HTML-код
  • Опубликовано: 26 ноя 2024
  • НаукаНаука

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

  • @followerOfJesus723
    @followerOfJesus723 2 года назад +17

    I mentioned you as being a great resource for beginning iOS developers. You do have the BEST explanation of MVVM on RUclips for people who are just starting out. Keep up the great work.

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

      Thanks for the kind words, Kwaku
      I appreciate it 😊

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

    one of the best IOS channels out there, so underrated man.. commenting to make YT algorithm stronger

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

      Thanks, East
      I appreciate the support 🤗

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

    This saved my day! I like your teaching style that's keeping the boilerplate code to minimum and is straight to the point! Great tut!

  • @Sakshisharma-kt1mt
    @Sakshisharma-kt1mt 10 месяцев назад

    very nicely explaining the MVVM architecture.

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

    Don't stop doing these, you're tutorials are my favorite

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

    This explanation finally set everything straight. Thank you!

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

    Best resource for IOS development !

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

    been looking for a clear tutorial for so long, thanks a lot bro, please make a video about mvvm with cordinator pattern

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

      Coordinator pattern is something I have in mind.
      Keep an eye out for it 😊

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

      Those are two different patterns no need for that video. When developers begin to make acronyms like MVVM-C it's because they think that MVVM is the architecture of the app, it's not. It's a pattern designed to solve a specific issue and it should be used at such.

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

    Thanks for the time and effort you put to these videos, greetings from an Emanuel of Argentina!

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

    Many thanks, that's the best explanation I've seen

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

    Very good explanation with appropriate examples, but it will be very handy if you would post also end version of project

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

    Best MVVM tutorial!

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

    Great video bro! Your explanation is very easy to understand! Keep doing these!! Thank you!!

  • @GK-ee7mw
    @GK-ee7mw 2 года назад +1

    Great video, very useful. One comment on the error observable - it seems like a not great pattern to observe the error and take an update with nil to mean logged in; we could have a bug if say the error was re-initialized to nil and the login hadn’t actually even been attempted yet, cause nil is the default state. What I’d suggest would be something like a isLoggedIn property on the view model that is defaulted to false, and observe that to decide to proceed if it gets set to true

  • @iOSDevAnjali
    @iOSDevAnjali 5 месяцев назад

    Very Informative!!

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

    Hi Emmanuel, This was indeed a very good explanation, but one thing i want to point out that, whenever you initialize your view model, and you have subscribe it in setup binder, then Observable object will call with nil value as well. Since you have used listener(value) in bind method as well. A simple print statement would do. Even before clicking on button goToHomePage method will call.
    Let me know if i am missing something.

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

      Thanks for catching that, Preeti
      In this case I would remove the listener(value) call in the bind function so that it only sends out the notification when the value changes after binding.

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

    Merci beaucoup Emmanuel !! So nice to finally get it !! it would be so good to hear your approach on RxSwift or combine :)

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

      Je vous en prie, Damsobaba 😊
      I actually have a video that covers MVVM and Combine.
      You can check that out here.
      ruclips.net/video/30LapcVtyBQ/видео.html

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

    You are amazing. Thank you for big font and your style of teaching!

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

    Please make an updated video where you show an array of listeners in an observable object.

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

      I’ll consider it in future, in the meantime, you can basically convert it to an array, append to the array, and loop through the array when you want to trigger a notification.

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

    Very good, I learn a lot!

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

    Passing data from view to another view's viewModel - Users List Page -> User Detail. How we pass data from view controller -> Detailed View controller ? - > Directly we can assign from Main to Detail view?

  • @АрсенийЗолотарев-б9щ

    Great explanation!

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

    Thanks for good Video! I started MVVM pattern recentry, this video was so good for me! Explained stroy was so good understanding.
    I want to know about one thing,Beginning of this video ,you said listener(s) get this →[  ] .
    How to attach it this code I didn't know...
    And main storyboard was there,should I make it in MVVM pattern ?
    If you have a time please teach me about this pattern in new video I think!
    Anyway I wish your new videlo anything!
    Thanks!!

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

    awesome explanation

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

    This is really Good Video. Thank you

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

    Really great stuff brotha

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

    hello Sir, I accidentally bumped into your channel and I have to say that I really enjoy your amazing teaching style and would love to see you make RxSwift and Combine !
    Also I hope you can make a in depth video about the situation where it allows multiple binding happens. Appreciate it

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

      Thanks, Ray. 😊
      I would really love to make a video about RxSwift but unfortunately it’s not a short term plan.

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

      @@EmmanuelOkwara that is fine. I appreciate your content. just one quick question, is it necessary to use binding method in MVVM or is there other ways to update the UI as well ?

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

      There are various other ways. You could use delegates, observers, closures,…
      But these methods will require you to manually notify the listening views.
      If you’re not careful, you may also find yourself referencing the View.
      *Your ViewModel should not depend on your view*

  • @Владимир-л9г6ф
    @Владимир-л9г6ф 2 года назад

    Thank's man! it's great👍

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

    Nice short tutorial. What about the testing portion?

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

      I have a video on testing in general but maybe in future I make more extensive videos.
      The core concept remains the same regardless.

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

    This is indeed an eye opener.

  • @kangajankuganathan4363
    @kangajankuganathan4363 11 месяцев назад

    what is the difference between [weak self] and [weak self] in

  • @АрсенийСторчевой
    @АрсенийСторчевой 2 года назад

    Thank you so much for your work!

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

    @ around 25:00 of this video, you make a `weak reference` to `self` on the DispatchQueue class that executes asynchronous task after few seconds. I wonder why? Since the `NetworkService` is a Singleton class therefore it never gets deallocated. You only use weak references to objects to make sure they are deallocated when they needed to be.
    Also.. I don't think that `DispatchQueue` class causes retain cycles. Although `asyncAfter` causes a temporary cycle, it does not cause memory leaks. You only have a cycle for 2 seconds and after that the cycle is broken.
    Looking forward for your thoughts about my comment. Thanks

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

      Thank you so much for the detailed response.
      I agree with all you’ve said.
      Using weak self is just a personal habit of mine. Rather than thinking about whether a retain cycle could be introduced or not, I always default to just making a weak reference especially when dealing with closures.
      In my opinion it’s just safest.

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

    sick intro dude

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

    Wait new full project bro thank you

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

      I’ll start a new project next year using MVVM design pattern.
      Keep an eye out for it 😊

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

    Well done Emmanuel 👏👏

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

    Great work !!!

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

    great explanation emmanuel is this binding technique called the "Box" Technique?

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

      I’m not sure what “Box” technique is 😬

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

      @@EmmanuelOkwara it is the same thing as property observers used by ray wanderlich just different name

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

    hello sir, I like your way but i have query on error and model in same bind?
    i can check error in same
    if no error then same bind i use for model
    is it possible to use same bind?

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

      Yes you can bind to whatever data type you want.

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

    Awesome video bro! Can you do Viper next?

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

      I’ll consider it 😊

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

      @@EmmanuelOkwara Thanks mate.

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

    Excellent explanation

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

    Please make a full video about network services encoding data GET POST PUT DELETE ✅

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

      I have a video covering GET and POST examples.
      ruclips.net/video/xsfzGt7k0rI/видео.html
      You can also check out this video teaching how to encode and decode your data
      ruclips.net/video/4TfCtY9NINk/видео.html

  • @AmitThakur-eg8kb
    @AmitThakur-eg8kb 2 года назад

    Hi Emmanuel, what a wonderful way of teaching you have. This video is really very awesome. Actually I want to say, the stuffs which you explained is understandable, but problem arises when dealing with new project from scratch, so you saying that you will write new project in MVVM pattern so it's already been a long time please upload that MVVM project, desperately waiting. Please.

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

      Thanks, Amit.
      I’m sorry I haven’t been able to make the video yet, I’ve been really preoccupied.
      I still have it in mind tho, and will create and release the tutorials as soon as I can. 🙏

    • @AmitThakur-eg8kb
      @AmitThakur-eg8kb 2 года назад

      @@EmmanuelOkwara Hey Emmanuel hope you doing good. Did you find time to create the video, it is already two months now.

  • @kwameagyenim-boateng2968
    @kwameagyenim-boateng2968 2 года назад

    when added binders, my controller automatically moved to the new vc on viewDidLoad. what might be the problem? I'm using a UINavigationController

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

      A signal is sent immediately you bind the view and view model.
      You could either add a check to confirm the value before navigating to the second page, or prevent the initial signal from firing when binding is initiated. (We added this in 19:34)

    • @kwameagyenim-boateng2968
      @kwameagyenim-boateng2968 2 года назад

      @@EmmanuelOkwara Fixed it. Thanks bro

  • @Rahul-jf5kf
    @Rahul-jf5kf 2 года назад

    Hi Emmanuel lets say on ViewDidLoad I want to call webservice which returns list of movies with each movie contains 20 fields but i want to display only 4 details out of it so in that case do we need to create another structure with 4 fields and map first list with 20 fields to new one with 4 fields and this seems lengthy. Instead if we use same structure reduces code.
    what is recommended way and what are the advantages

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

      Hello, Rahul
      You don’t need to modufy/create a new struct.
      You can simply set a maximum value for numberOfRowsInSection
      This way, it’ll display first X items while your full data is still available

    • @Rahul-jf5kf
      @Rahul-jf5kf 2 года назад

      @@EmmanuelOkwara thanks

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

    Amazing. There are a lot of mvvm tutorials on RUclips, but I still think this is the best one. Clear and to the point but not too fast. ;)
    But I have 2 questions:
    1. In others mvvm tutorials, some of them say that the controller is still here and the controller owns the view model. But when you explain mvvm, nothing seems to own the view model, its just 3 components. Can you clarify this a little bit?
    2. I am studying for interview for iOS developer, just thinking it would be a great idea if you can make a video about interview mock questions in the future?
    Anyway, thank you ;)

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

      Thanks, John 😊
      1. I mentioned that in UIKit, we usually have the View and Controller together as ViewController. In this sense, you can choose to say that the controller owns the ViewModel.
      I mostly said View just to avoid introducing the word “Controller” which is not included in the acronym “MVVM”
      2. Best of luck on your interview 💪😁
      Also, I’ve really considered creating a series dedicated to interview preparations. I’ll definitely get to that next year.
      Thanks for the suggestion 😊

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

    Pls put video on RXSwift

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

      I’ll add this to my TODOs.
      Thanks for the suggestion, Divya 😊

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

    Hi Mate...Can you please make a video on MVVM-C with data passing. It will be great help. Thanks in advance

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

      I have this in mind, Sagar.
      Thank you 😊

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

      @@EmmanuelOkwara Thanks mate.. Urge you to demonstrate how we can pass the data as well… I am but confused cause if coordinator gonna take care of navigation and passing data then what is the use of VM.. maybe silly query but yeah i have that 😊

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

    Thanks for this great video :)

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

    are your videos standalone or part of one project?

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

      This particular video is part of a series called iOS Development with Swift
      Here’s a link to the full playlist.
      ruclips.net/p/PLgBVHL8joMCslhJPyp2Wzzh5ZO9bmRkK-

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

    Thanks for the great tutorial. One question, For a example If I want to populate tableview with list of data in HomeViewController, can I use the same HomeViewModel? Or do I need to create another ViewModel class for this?

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

      You are a programmer, you can do absolutely anything 💪😎
      On a serious note tho…It’s best for each view to have its own ViewModel, so for your tableview, the cell will have its own ViewModel that accepts only data that it needs.

  • @suee-u2c
    @suee-u2c Год назад

    awesome

  • @KeerthanaG-j2h
    @KeerthanaG-j2h Год назад

    Hosssom Tutorials...!!!

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

    thank you

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

    vert good

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

    🔥✊

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

    Great tutorial, Can you make a video for multiple subscribers subscribing so that it will make better understanding.

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

      Sure. I’ll add it to my todos 😊
      Happy New Year, Arun 🥳 🎆

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

      @@EmmanuelOkwara Thanks Emmanuel.

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

    Great video to learn MVVM..@Emmanuelokwara Thanks

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

    good video but let me point out this is not actually an MVVM pattern that you are following. MVVM states that ViewModel is responsible for converting models into displayable objects and any logic that goes into converting a model into a viewable object should be handled by ViewModel itself. Hence your ViewModel should always have a reference to a View and a Model and it should be responsible for your rendering out model onto your view that is passed onto the ViewModel from your Controller. What you are doing is again passing that functionality back to your view controller and I don't understand why and how this is MVVM? Please first learn yourself about what actually MVVM is. I can suggest a few courses from very PRO developers who also work directly with Apple. But sorry to say this is a very bad implementation of MVVM.
    You already have created user model to encapsulate user data and then you are declaring more variables to pass that information back to your view controller which is so stupid. Why the actual fkc your viewcontroller needs to see user model and any logic that is required for user model to be displayed on to your view? You have welcome message and then you are creating another string variable to hold that message? What the actual heck are you trying to do by complicating things without any reason.