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.
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.
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
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.
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.
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
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.
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?
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!!
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 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 ?
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*
@ 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
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.
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?
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
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.
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. 🙏
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)
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
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
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 ;)
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 😊
@@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 😊
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-
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?
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.
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.
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.
Thanks for the kind words, Kwaku
I appreciate it 😊
one of the best IOS channels out there, so underrated man.. commenting to make YT algorithm stronger
Thanks, East
I appreciate the support 🤗
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!
I’m glad you liked it, Daisaku 😊
very nicely explaining the MVVM architecture.
Don't stop doing these, you're tutorials are my favorite
I’m glad to hear it, Zach 😊
This explanation finally set everything straight. Thank you!
I’m glad to hear it 😊
Best resource for IOS development !
been looking for a clear tutorial for so long, thanks a lot bro, please make a video about mvvm with cordinator pattern
Coordinator pattern is something I have in mind.
Keep an eye out for it 😊
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.
Thanks for the time and effort you put to these videos, greetings from an Emanuel of Argentina!
Thanks, Emanuel ✊🇦🇷
Many thanks, that's the best explanation I've seen
I’m glad you liked it 😊
Very good explanation with appropriate examples, but it will be very handy if you would post also end version of project
Best MVVM tutorial!
Great video bro! Your explanation is very easy to understand! Keep doing these!! Thank you!!
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
Thanks, G K
I agree with you. 💯
Very Informative!!
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.
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.
Merci beaucoup Emmanuel !! So nice to finally get it !! it would be so good to hear your approach on RxSwift or combine :)
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
You are amazing. Thank you for big font and your style of teaching!
My pleasure 😊
Please make an updated video where you show an array of listeners in an observable object.
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.
Very good, I learn a lot!
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?
Great explanation!
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!!
awesome explanation
This is really Good Video. Thank you
Really great stuff brotha
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
Thanks, Ray. 😊
I would really love to make a video about RxSwift but unfortunately it’s not a short term plan.
@@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 ?
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*
Thank's man! it's great👍
Nice short tutorial. What about the testing portion?
I have a video on testing in general but maybe in future I make more extensive videos.
The core concept remains the same regardless.
This is indeed an eye opener.
I’m glad you found it useful 😊
what is the difference between [weak self] and [weak self] in
Thank you so much for your work!
@ 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
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.
sick intro dude
Thanks, Ivan ☺️
Wait new full project bro thank you
I’ll start a new project next year using MVVM design pattern.
Keep an eye out for it 😊
Well done Emmanuel 👏👏
Thanks 😊
Great work !!!
great explanation emmanuel is this binding technique called the "Box" Technique?
I’m not sure what “Box” technique is 😬
@@EmmanuelOkwara it is the same thing as property observers used by ray wanderlich just different name
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?
Yes you can bind to whatever data type you want.
Awesome video bro! Can you do Viper next?
I’ll consider it 😊
@@EmmanuelOkwara Thanks mate.
Excellent explanation
Thanks, Dee 😊
Please make a full video about network services encoding data GET POST PUT DELETE ✅
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
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.
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. 🙏
@@EmmanuelOkwara Hey Emmanuel hope you doing good. Did you find time to create the video, it is already two months now.
when added binders, my controller automatically moved to the new vc on viewDidLoad. what might be the problem? I'm using a UINavigationController
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)
@@EmmanuelOkwara Fixed it. Thanks bro
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
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
@@EmmanuelOkwara thanks
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 ;)
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 😊
Pls put video on RXSwift
I’ll add this to my TODOs.
Thanks for the suggestion, Divya 😊
Hi Mate...Can you please make a video on MVVM-C with data passing. It will be great help. Thanks in advance
I have this in mind, Sagar.
Thank you 😊
@@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 😊
Thanks for this great video :)
It’s my pleasure 😊
are your videos standalone or part of one project?
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-
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?
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.
awesome
Hosssom Tutorials...!!!
thank you
vert good
🔥✊
Great tutorial, Can you make a video for multiple subscribers subscribing so that it will make better understanding.
Sure. I’ll add it to my todos 😊
Happy New Year, Arun 🥳 🎆
@@EmmanuelOkwara Thanks Emmanuel.
Great video to learn MVVM..@Emmanuelokwara Thanks
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.