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

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hey guys welcome back to my channel for those of you who are new my name is manuel and today we're going to be learning about the mvvm all right and our last video we learned about the mvc so if you haven't watched that then maybe just take a few moments and just go watch that all right so what is the mvvm the first letter stands for model and just like we said in our last video this basically represents our data so an example typical example is having a user object that basically describes the various attributes that a user has so like a first name a last name and email and also certain actions that the user can perform so for example we could have a method in our user model called save user or update user name something like that you know so that's what our model is about right now um the second one we have is the view and very simple as a view says whatever we can see all right so um our buttons our texts fields our switch controls whatever objects you can see on the screen right that's what our view is about and finally unlike the mvc we have something called the view model and just like the name implies view and model so it basically means a model for a specific view so if you remember from our mvc we had a user object with all of the user attributes right and a view or all different views that are available in the app has access to all of the user objects right but for a view model of the view model design pattern every view has its own view model and basically what the view model is is um all of the attributes or all of the methods that are directly related to the view itself so it's not going to have all possible attributes that um an object has but it's going to only contain attributes that are specific to a particular view all right we're gonna see um exactly what this means in a bit but just to give like a general picture imagine that we had a user object with um first name last name email phone number uh and some other extra fields location and likes now if we have a table view cell for example where we only display the first name and the last name for the mvc would have access to all of these attributes i just mentioned for the user but for the view model we're only going to have access to the first name and the last name and with that if let's say for example some changes were made to maybe the email or whatever just changes that made to the model in general the view is not going to be aware of this and you wouldn't have to make any changes whatsoever to the view because the view has absolutely no idea what is happening with the model all right so we're going to actually see this in action so don't don't worry too much if you didn't really understand what i said now before we actually get into code i'd like to just give sort of an overview of just how um these connect with themselves all right so again we have our model our view we have a viewmodel right so uh let's say a user performs an action the viewmodel is going to be aware so the viewmodel you can think of contains our business logic so now that the viewmodel is aware it's going to perform whatever kind of logic is required for that particular data so let's say for example you want to do a login or um you want to get some data from your storage or whatever the view model does that all right then when it is done it basically updates our view but now unlike our mvc the update isn't done directly it's done using um a binder if you will and basically what this means is that the view model is not aware of the view now um remember from the view um the mvc we had in our last video whenever changes are made or whenever um the view needs to be updated the controller directly modifies the view so the controller is aware of the various objects the various um attributes that are available in the view now this is different from for um the mvvm because in the mvvm um the view model performs whatever operations and when it is done it updates a value in the view model now when this value is updated it sort of sends a broadcast or a notification if you will that this particular object has been changed now when this update or this notification is sent out whatever views are connected or bound to that object all of those views that are bound are going to be notified then the moment they are notified then they can of course directly update their view so uh just to give a general flow imagine that um we perform we're trying to get a logged in user for example um the view model goes and gets the logged in user from maybe the local storage and when it's done it just updates the user object and when it updates the user object that's all the view model doesn't do anything else it just updates the user model within its class or scope now when it does that somehow behind the scene the view controller because in ui kits we have like a view controller but the view right is going to be aware automatically that the viewmodels object has been changed and because it is aware it will now update the label and then change the maybe name or whatever property all right now don't be so um bothered about how this works but definitely going to go into code and you're going to see how this works in action it's pretty interesting don't worry so um yeah that's how the view and the view model connect with themselves so the view just to stress the point the view is aware of the view model but the view model is not aware of the view so whenever the view model makes changes or whenever changes are made to the view model the view is going to be aware so if you change some objects or whatever values some properties in your view model your view is going to be aware but if you change properties in your view your view model is not going to be aware it's not going to care because it doesn't speak to the view model directly all right so just just imagine that you make some changes and you just shout i don't care who listens i just shout hey i've changed so whoever is in the background can listen and do whatever they want to do you don't care whether or not they react all right that's how the view model is it is completely independent but the view has to be aware of the view model so that whenever changes are made the view can update um it seems like i've spent a lot of time explaining this but i just hope that makes sense um so yeah the same way the view model also connects with the model so just like the um the view is aware of changes in the view model the view model is aware of changes in the model so the view model is sort of in between the um view and the model and what this does is whenever so there are two things involved in the view model um only objects or only attributes that the view needs are available so just like if you remember from the initial example i gave if you have like a user object the user object can have like 50 different attributes but the view model is going to have just two first name and the last name all right so the view model gets that data from the model so it connects with the model and is able to update the value of the model or even retrieve values from the model all right so um that's how it works and again the model can notify the view model if changes are made in the model okay so i think i've spent some time explaining how the entire um the model view and view model connect with themselves so um let's actually go into code and i'm sure everything is gonna make sense to you very shortly all right so um i'm just gonna open up um the starter project and this is actually the same startup project that we had in our last video and i'm going to leave a link in the description so if you want to follow along then just feel free to download the startup project and we can move along otherwise you can also just watch and learn because um the idea of this is to give you a visual understanding of how you could write your mvvm code okay now before i actually go into the implementation i'd like to just do a very quick run through of the code base just in case you don't want to go check the previous video so uh but basically if you open the main.storyboard we have two view controllers as you may consider as our view in our mvvm all right so our view we have our login screen and we have our home screen which basically simulates a um like the landing page of a logged in user all right so here we have our email and password and when you click on this button we want to go to the next page and then want to show um hello and then the full name of the user all right so um if you go over to the login view controller you're going to see that we have the email and password connected we have a button a function here that's executed whenever the login button is clicked then this touches began so we can resign the keyboard when you click on the body of the screen all right so um if you go to the home view controller we have nothing serious going on here we just have a reference to our welcome label which is that hello welcome label in the middle of the screen so this is what we're gonna this is where we're gonna set the name of the user all right so now we have our view all set up the next thing we want to do and sorry before i just go any further um when we're talking about mvvm uh some people ask the question okay but i still see a controller yes you do because in ui kits we basically have our viewing our controller uh basically tangled into a view controller all right but just imagine that as you view right then we have our view model then we have our model okay so uh let's go ahead and implement our view so uh just quite similar to our last video we're going to create a struct and this struct is going to be called user all right so this is going to be our model so how do we create our user model very simple just say user and we're going to create a couple of attributes so we're gonna have first name we're gonna have last name we're gonna have age age is going to be an integer what am i doing here then um let's add email i think we're just going to stop over here all right so this is our user object and again user objects can be really crazy like it could be so long imagine if you have um uh if you're working on an actual code base like a big project the user object can be really long so this is why the view model can actually be really helpful because out of like 30 different attributes i only need two so why do i need access to all of them alright so um this is our model okay so uh for the view model now we have our view controller here which we are thinking of as our view we're gonna also need to have a view model so what i'm going to do is i'm going to hold down command n and i'm going to create a new swift file which i'm going to call login view model okay so this is going to be our login view model now we have our login view controller we have our login view model what i like to do is i like to put both of them in a single group just so both of them are grouped together so on this i can call login right or login view if you will since login view is in both the view it's remodel so i'm just going to put that in here so now we have our login view and in our login view we have a login view controller we also have our login view model all right now for us to implement our login view model i'm just going to create a class and we can actually just make this final so final class and final class login view model now before we get into implementing the um logic to our view model or a login view model there's one thing we need to do now if you remember from the diagram i mentioned or the diagram i showed about the mvvm we basically had a relationship between the um the view and the view model and basically the way they communicated was through a binder or basically um the view model is able to make some changes and then broadcast some uh updates or notification to whoever is subscribed right so how do we do that here now binding can be implemented in different ways in this video what we're going to do is we're going to use a method that is very simple and that's using an observable right so we're going to create an observable object class and we're going to use that to basically uh send a notification whenever uh changes are made to a particular object or a particular attribute right but apart from that there's also something called an event bus and um for people who also like rx swift there's the rx coco and there's also combined and actually combined is one method i'd love to make a video about in future so maybe just let me know if it's something that you're interested in learning but like i said in this video we're going to be learning using a simple class that we're just going to create an observable object class all right so what we're going to do is we're going to just take a break from here the view model and we're going to implement this observable object class and that's pretty simple to implement we're going to create a new file and this file we're going to call observable object okay so we're going to create that and now we're going to create a class called observable object and now this class we wanted to uh basically have or support different types so we're gonna put this a t in this um angle brackets all right and actually if you're not aware of what exactly is happening here what we're doing is we're using something or concept called generics and actually have a video on that i'm going to leave that in the card right at the top so if you know if you don't understand how generics work then um feel free to just check out that video i tried as much as possible to explain it as simply as possible so uh yeah that's what we're basically doing here one is to be able to support multiple types so not just a single type one support like integer um string boolean even custom structures all right so that's why we're using this so we have that the next thing and we can actually just go ahead and make this final okay good so now we're gonna have a property here called value and value is going to basically be of type t so whatever the type is or whatever the class type is that's what this value t is gonna be now i'm gonna make this optional just in case um or just so that it supports nail values so you could um basically create an object and then pass a nail okay so that's that the next thing we're gonna do is we're gonna create an initializer and this initializer is going to take in the value so the value is going to be of type optional t okay so now we just say self.value this is going to be equal to value pretty simple okay so just like i mentioned um when uh someone or a particular object observable object is going to be triggering a notification you need to be listening you need to be bound to that particular observable object so that you are you are aware um whenever changes occur so i'm going to give a real life example imagine that okay we have a television right and um we have a station in nigeria we have a station called like channels or more popular we have cnn right so cnn is a channel that displays news okay now if you don't have your television on and if you are not subscribed to the cnn channel even though news are going to be cast you're not going to know right so um if you if you are sitting in your living room and they just start publishing the news that there's a zombie apocalypse happening you're not going to be aware but if you have subscribed to the channel or you are basically bound to that channel to cnn then when they like post the news or read the news that there's a zombie apocalypse you are immediately going to be aware and then you can just run out to the streets and pick your guns and a knife right so um that's basically what we're doing here we have our value here which is you can think of as your news then we're going to create a a function that allows other people to be able to listen to or subscribe to the news so uh what we're going to do is we're just going to call this bind all right so we're going to call this bind and when you're binding we're going to pass in a listener oops what did i do so i'm going to say listener and this we're going to say escaping and the value that we're going to be returning because when we bind we want to also uh basically send back the news that is within the channel okay so just gonna put a t right there and then we're gonna say void so this is our closure that is basically going to inform whoever is subscribed that or whoever is listening that a particular change has happened all right so now that we have our listener we're going to have to create a private can create a private variable over here that we're going to call listener and this listener is going to be of type this it's going to be of this particular type okay so we're just going to copy this and right here we're just going to paste this and we're going to make this optional because initially it's going to be nil all right so uh this is going to be optional so now that we have our bind method what we want to do is basically set our listener to be whatever closure is passed in so here we're going to say self dot listener is going to be equal to listener all right and the moment you bind like the moment a user binds to this particular observable object we can actually just trigger a or just send a notification instantly so the moment you you subscribe to uh cnn we just get the news real well the current news immediately all right not waiting for a change so what we're going to do here is we're just going to say listener and then we're going to pass in value that's it okay now there's actually something we can do here to improve this but i'm going to leave it here just so things are basic but basically what we can do here is we could make our listener to be an array instead of a single object so now we have it as a single value or a single variable meaning that one person can subscribe to that channel but in the real sense you can have multiple people subscribing to that so you could have this as a listener and then make this an array like this okay oops not like that like put an array like this all right so but uh just for simplicity sake i'm just going to leave it as a listener like this so just imagine that you're going to bind to the object and just going to have just one instance of the bind but if you of course want me to go more in depth feel free to just leave it in the comment section so i can you know make an updated video all right so now we have created our observable object and you can see how very simple this is you can actually use this in many other projects you have and um of course you can decide to improve it as you will good so now we have our observable object what we're going to do now is we're going to head back to our login view controller right in our login view and now we're going to create an instance of our view model because remember what i said the view is aware of the view model meaning it has direct contact with the view model and the reason is because we need to be able to basically connect with the different attributes that are in the view model okay so what we're going to do here is we're going to say private let and view oops view model and this is going to be login view model all right very simple so this is going to create an instance of our login view model login view mode oops login view model just like this beautiful so now that we have this what we're going to do next is before we go into implementing the um login feature on the view of this login view controller i want us to actually implement the logic in the back of the business logic and the network um part of things okay so we're gonna go over to our login view model and before we actually do that let's actually just create our network service and this is gonna be pretty similar to what we had in our last video just go ahead and create a network service and basically what this is going to do is it's going to help us simulate a back end all right so like making a network request all right so we have on network service and right here we can just go ahead and create a final class called network service and here we're going to make this is i'll create a singleton here called static let shared and this is going to be equal to network service then we're going to have a private in it like this so we don't create an instance of this then now we can create a function called login because that's the first thing we want to do here right so this is going to have email type string we're gonna have password of type string as well then finally we're gonna have a completion handler that is basically going to tell us when our login is successful and here we're going to just pass in a boolean so the boolean is going to tell us true or false depending on whether or not the login was successful great now in order for us to simulate a network request just like a delay we're going to say dispatch queue dot main dot sync after i'm going to sync after a deadline of like two seconds all right now now after that we're gonna do basically is we're gonna check if email i missed something here oops i did so supposed to add completion like this all right so we're gonna check if email is equal to test test.com and password is equal to password oops so if this is the case what we want to do is just simply call our completion and pass in true otherwise otherwise we're just going to call our completion and pass and false pretty straight forward good now um apart from that we are also going to have to create a user object here that's basically going to simulate our logged in user all right so this is going to be of type user and we're going to make this optional because initially it's going to be no because no user is logged in all right and um let's see let's see let's see so here what we're going to do is we're going to say user is going to be equal to user and we need the object and here we're going to say first name as a manual last name is quora email is going to be test task.com age is going to be 24. and yeah that's it for this so this is going to be this and here we're just going to say user equals now sweet so this is going to simulate our login event right so this is like going to the backend now um just to make sure that there's no network linkages or whatever even though he's in a single term we just add a weak self over here and put an n and just like i said in the last video i have a video explaining like what this is so if you're not aware then i'm going to leave a link to that as well so you can check it out right so self like this good now we're going to do um basically implement the okay let's let's hold off on that for now good so this is our network service and now that we have that we can actually go to on our login view model and here we're going to implement a method to login and here we're going to say func login again this is going to take an email but this time it's going to be coming from our view and then the password is going to be coming from the view as well this is going to be of type string all right so that's that and right here we can just use our network service service.shared.login and here we pass an email here we pass in password and in our completion we're going to have a success and here we're just going to say weak self again and finally at this point we want to basically check whether or not it was successful and if it is successful then we want to go to the next screen where we're going to display the welcome message but if it is not successful we want to display basically just print an error message in the log right now but unlike the mvc we cannot directly update our um view right so remember the viewmodel is completely independent it's not aware of anything that's happening in the view um in the view controller it's not aware at all it doesn't even know the type right so what we're going to do is right here we're going to create a variable called error and this error is going to be an observable object so that's one difference that we need to note so this is going to be an observable object and the type is going to be string okay so this error um this error variable is going to basically have a value that is of an optional string and this is an observable object all right now we're going to see how this works in a bit so this is going to be equal to observable object and then we can initialize this with nil very simple very simple like that so now that we have this we've gotten our network response all right so what we can do is we can update our error message to basically hold an error message if the login was not successful so how do we do that we're just going to say self dot error is going to be equal to and now we're going to check if it is successful so if it was successful we're just going to pass nil right so it means that there's no error okay but if it is not successful we're gonna pass in an error message and say invalid credentials all right very simple so you can see we're making a network request and based on the response we get if it is successful we're gonna update our error message to say um to have nil as no message or an error message is a string now this thing isn't working because error is of type observable object now if you look at our observable object you notice that we have something here called value which is of the type that we need so rather than trying to update this rather than trying to update the error like this we're going to be updating the value instead okay so the value of this error message is going to be this is going to be sorry nil if it is successful or invalid credentials if it is not now there's one thing that we forgot to do in our observable object class and i'm just going to go over there and can you imagine what that is if we look here we properly initialized very good we properly got access to our listener which is very good but we don't actually send a notification whenever changes occur so if a change should happen um to our value object we don't know so how do we do that we're just going to come over here and we're going to implement our date set property so whenever a value is set we simply want to say listener and this is optional so listener and value so what this is doing is whenever you the value of this changes then it's going to just use our listener or basically broadcast the notification using our listener this is going to broadcast it to whoever is listening all right so yeah this was something that i missed good so now let's get back here so yeah if it is successful set the message the error message to be nil if it is not successful then set the uh just set the error message to be invalid credentials great so now we're done with the the login view model what we can do now is go over to our login view controller and what we're going to do over here is whenever the login button is clicked now for this video i'm just going to completely disregard validations and all those things just because that's not the scope of this study so what i'm going to do is i'm just going to go ahead and use our view model so now i'm going to say viewmodel.log in you can see that we've basically removed any kind of our business logic out of the view controller and that's going to make this more cleaner it's going to make it more specific to the view tasks which you should be executing right so uh for the email we're just going to say email password is going to be passwordfield.text sweet so this is going to perform the login but now we've performed the login and actually this is optional so we're going to need to have both of them we can just go ahead and use a guard so guard let email oops email be equal to email field dot text and uh now i have let password equals password field dot text and else i can say print please enter email and password even though i know both of them are going to be there i'm just just doing this anyhow um so here we're just going to pass an email instead of email that and password is going to be password good so now when you click on the login button it's going to use the view model to perform a login but um remember the view model doesn't tell me directly it doesn't update the view directly so how is the view going to know that the view model has changed that is very simple what we're going to do here is we're going to create a func so just create a private function here called setup binders and basically what's going to happen in the binder is we're going to say we're going to basically bind to whatever object we want to listen to right so bind to whatever channel bind to cnn bind to bbc bind to whatever channel you want to listen for updates right so here i'm just going to say view model that's error which is basically what we want to listen to right so dot error and then dot we're going to have a function called bind right so we're just going to say bind like that and now we can just open our bracket like this that is basically our completion that we're passing in and here we're going to say weak self and and here we can just have our error okay so when we bind we're basically subscribing to that particular channel basically subscribing to the error the error attributes that is in our um what did i just do there our error attribute that is in our view model so this error should be before like this okay so if we go ahead and look at the type over here we're going to notice that the error is actually of type optional string but this is optional optional meaning that we have something not quite right now if you go over to the error message or the error variable over here we have this as an optional string which is good i want this i want the error type to be an optional string but it is returning double optional meaning that if we go over to our observable object right here we're actually forcing or saying that every value must be optional so what that means is if i don't want to have an optional string over here and i create an observable object then this is going to return an um optional error right so like if you go over to the login view controller hold down alt and click on this you see that this is optional but i don't want this i want the type that i specify in my view model to always be the same as is in our observable object so how do we do that what we're going to do is go back here and everywhere we have this optional we're just going to remove that so we don't want it to be an optional type by default want it to always be the exact type that was um used to create the observable object so i'm just going to go ahead and build this and if you go back to the login view model you're going to see that there's no error minion is still good so we are able to create a nil object because the type is an optional string now if we go back to our login view model or view controller rather and hold down option click on this you're going to notice that this is optional string if we go to our login view model again and this time i remove this and build this is going to actually fail from here because it can be optional it cannot be optional so here if i do this you're going to see that it's just string right so i hope this is some you've learned something from my mistake over here and then guys i actually apologize i'm shooting during the day so there's a lot of noise you know how lagos is so there's a lot of noise outside so i apologize okay good so um yeah this this is good so let's build again make sure everything is good and now that that is okay we can go back to our um view controller and here what we want to do is at this point we're notified when there's or when the error value changes so now we're just going to check if there's an error so if that error is equal to error oops so if there's an error then we're just going to print error otherwise we're going to navigate to the login page so we're going to say uh go to home page and this is a function we're going to create right now so private func um go to home page so here we're going to create a controller equals storyboard.instantiate viewcontroller with identifier and the identifier is going to be home view controller we're going to copy this paste this right here and here we're going to say present oops present and we're presenting the controller animated true we need no completion so this is good now we have to make sure that we set up our binders so right now if you did load we're just going to say set up binders good so this is this seems good so let's actually just run this to make sure that everything works smoothly then i'm gonna go over this one more time so now i'm gonna write the wrong email wrong password i'm gonna click on login after two seconds we should see something here which is wonderful so now i'm going to put um a valid email so i'm going to say um test test.com and password is going to be password so i click on login and after two seconds it should bring up wonderful great so now let me just do a very quick run-through um of our flow just so that um you understand exactly what is happening so now over here we have our view right in our view we created an instance of our view model okay so um after doing that we had to set up our binders so setting up a binder you can think of as basically subscribing to a particular channel so that whenever there's an update you are aware and since at this point you are aware whenever a change occurs you are able to basically update your ui and do whatever you want to do um considering the updated value okay now again the view controller doesn't um of the view model which is what we have over here does not directly update our view controller instead what it does is we're able to modify a particular variable that the view controller is listening to and then that variable just sends a broadcast whenever changes are made right and the observable object is what allows us to be able to send a broadcast to a particular listener and again this is something you can use in many other projects you have and like i mentioned there are different ways that we can do this you can use rx swift you can use combine um you can use the event bus like different options but this is very simple to use and it doesn't require any third-party dependency right so um now that we have that done we have our network um request done over here or at least a mock in our case and when that is done we simply just get a response and we are able to update our variable which is the one that the view controller is listening to and when we do that the view controller simply reacts that's it that's exactly how the view model works you can see that it is pretty sweet at least the fact that it is a reactive kind of programming is pretty awesome so we're going to do now is we're going to run over to our home um view our home view controller and we're gonna implement the view model uh the mvvm design pattern to this particular page so again what we're gonna do is we're gonna create a new folder a new group and this we're going to call home view all right now in our home view we're going to have the home view controller again we're going to have our home view model all right so now that we've created that we can just go ahead and create a final class if you will and then this is going to be home view model just like that then here um just like i mentioned remember the view model is going to contain properties attributes and methods that are directly related to the view so we don't bring whatever we don't need so in our case we're gonna need um we can say we're gonna need our first name or we just say uh welcome message right we're gonna need our welcome message and this normally we would have written as a type string but since we're gonna we're trying to make it an observable object we're gonna say that this is an observable object and this observable object is going to be of type string we can make it optional again and this is going to be equal to observable object and in bracket we can just pass in now all right autumn so this is going to be a welcome message now what we can do is we can create a function here that says um get logged in user all right now this get logged in user is basically going to um use our network service and it's going to get a logged in user but before then we have to go to our network service and we're going to implement the function to do that so we're going to say func gets logged in user and this is going to return user and here we already have user in this class so anna this is actually public so we could just directly access it but i'm just going to make this private in here we're simply going to return user now this is optional so i'm just going to force this because i'm extremely lazy and i'm sure that it exists good so now we can go back to our home view model and right here we're able to just say dot shared dot get logged in user now this is gonna return a user object right so i'm just gonna say let user equals this but now just like i mentioned in the view model we're not going to be working the view the view isn't going to be working with the model directly the only thing that is aware of the model is our view model and the view model is going to basically expose what the view needs and in our case the only thing the view needs is the welcome message now the welcome message is composed of the first name and the last name from the user object which is all we're going to be getting from here so what we're going to do is we're going to say self dot welcome message dot value and this is going to be equal to a string so this is going to be hello and then we're going to say um this this where the first bracket is going to be user dot first name and this oops the first name and the second one is going to be user dot last name okay so again the user the view is absolutely not aware of the user model okay but it is aware of the view model which is only what it needs it only needs the welcome message if we needed for example the first name we could just add first name over here and if you needed last name we can add last name over here and then here we just say self.firstname equalsuser.firstname and self.lastname equals user.lastname all right but in this case it doesn't need them so we don't we don't talk about it don't just yeah that's it all right so um that's basically what is happening over here so um here we've gotten our welcome message and the idea is now that the welcome message has changed it should trigger a notification so whoever is subscribed is aware so how do we subscribe again just go over to your um view controllers actually get rid of all of these necessities and at the top we're going to create a reference to our view model so view model is going to be equal to our home view model and here we're simply going to say view model dot get logged in user all right so now that we've gotten the logged in user we know that this is um like is very fast um so what we're going to do here is we're just going to say welcome label dot text or actually so um now that we've gotten the logged in user remember when you are trying to if you want to be aware of changes you have to subscribe so it's something you always have to remember so here we're going to create a private func and say set up binders and this set of binders is going to be binding what so we want to simply listen to changes on our welcome message so the welcome message and we're going to say dot bind and we can just open our curly braces over there add a weak self in and um this actually gives us remember because we in our completion we always pass in the value like we always send back the value that um was updated so we can actually just fix that and put no actually not there should be after the week self so we can just say message over here and here we can simply just say uh welcome label dot text oops equals message awesome so now we're gonna set up our binder set up binders so we're gonna set up our binders before we actually get our logging user so this guy's gonna be aware so now let's go ahead and run this and okay i missed something over here so just weak self so you have to say optional self and uh we're gonna run this so what we expect is when we log in successfully so test at test.com and password when we log in successfully and go to the next we should see hello emmanuel acquire so i'm going to click on login after two seconds it comes over here and we have hello emmanuel acquirer so that's basically how the model view view model works it's pretty i i personally like it because especially for the fact that it reacts right it doesn't you don't have to directly um directly be aware of changes or whatever is happening in the view controller this guy is completely independent and because of that you can like test this guy very well you can test it very easily so um yeah that's that's actually it for uh model view mvvm for short and uh if you have questions by all means go ahead ask in the comment section and i'm actually gonna be working on a new project and i'm thinking that's gonna be a next year project i guess uh and that i'm gonna build with mvvm all right so in our last in the last um in the uh project we built earlier this year um the yummy food authoring application we use the mvc and then the next one i'm going to be building next year we're going to be using the mvvm so if you haven't subscribed go ahead and smash the subscribe button click on the little bell so that you you are notified immediately my new videos are up so you know just subscribe to it find right so yeah that's it that's it and um you guys have an amazing week bye [Music]
Info
Channel: Emmanuel Okwara
Views: 202
Rating: undefined out of 5
Keywords:
Id: sLHVxnRS75w
Channel Id: undefined
Length: 47min 44sec (2864 seconds)
Published: Sat Dec 18 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.