In your system you can talk about the life cycles that we have in view control.
There are many many different life cycles and they essentially define how a viewpoint or a goes through
its different stages.
So this is I will try to explain as many of them as I can for you.
The school two weeks.
And I'm going to make a new application let's call this one our view control are View.
That's right the whole thing View control life cycle is so like that it's and I'm sure by now you have
definitely seen or have used the view that the law is the default thing that we always have in here.
Now beyond that there are so many many other wants and what I'm good at doing this lesson is I'm right
all of them down.
And then we're going to go ahead and print something in each of them to find out which one comes first
and then they're going to reorder them so we get a sense of what's happening.
So another one is actually called viu will appear.
So the mule will appear and that is super dart of view will appear because it's a subclass of the few
control of course.
So let's see what you will appear does.
And what's the difference between the ones that they say view something something load or view something
and appears.
The difference between these two is this Indos view is low that essentially it means all of your objects
are created but they are not visible to user or they're not going to be visible just yet in the ones
that they say View will appear or view did appear.
It means that something is going to be visible or something has become visible some little right in
here.
You will soon be shown.
And this is often useful for are useful for van right before transitioning into another view controller.
This would be very useful for the moment that you're going to another view control and you want to have
something happening and other lifecycle that we have in here is viewed with a Ph.
And obviously the name of it is suggesting what it does.
This is essentially for in your view has loaded all the objects are initialized and now it is being
shown on the screen to your user.
So you might be wondering what's the difference between viewed it appear and view lot.
And what should I use in view that appear.
So when you look at the new law essentially everything that you want has been initialized and allocated
but they are not being visible yet.
And there might be a little time between that and when they are being you know visible.
So for instance if you want to start a timer start a timer or run an animation.
This would be a much better place because there it will happen once things are being shown on the screen.
Now in saying that there is a little bit of a downside and something that you have to be careful about
what happens just once only once in the life cycle of your application.
So if you load an app and you go from one view control to either one that only happens the very first
time you're going to that view control both views that appear happens every time that that you counter
is being shown.
So if I go to my storyboard
and imagine I have this main view controller that has a background with a color such as says I have
a new installation of exclude all my colors are gone.
So I have to remake them so they have this fun with some sort of a green background.
And I have another view controller on this one I'm going to maybe make it a little bit pink.
OK.
So this is my other one.
So the moment the app runs this view is going to be loaded.
And that's the last time that that cycle happens.
And then when I have a Segway and I go to the other one whenever I go to the ping point of view loads.
Now if I had a button to go back when I come back to the green one it is not viewed that load anymore.
It is the view it appears that happens over and over and over.
So keep in mind that the view that happens only once.
Why would it appear.
Happens each time that you are land in this view controller.
So that's something that you have to keep in mind because sometimes you know you shouldn't try to initialize
or allocate something in the view that appear simply because we run multiple times.
If you do that now as you can imagine view you appear simply happens after view will appear.
And there's another one that happened somehow between these two or somewhere between these two.
And that is the one that they call view tape.
Lay out some views.
So this is superdad view that lay out some views.
This is essentially where all the pieces of the view are laid out and what laying out means is something
that they're going to talk about it a lot in the coming lessons in Arthur lay out but essentially means
this if you have an idea let's go ahead and say by then and this button is meant to be in this particular
place with a bad going for it I can see it.
And this is not currently being designed for iPhone 8 and you're running your app on let's say iPhone
X..
So what should it do and where should it be laid out.
So someone else will decide about that.
And that is this lifecycle.
This is the one that this is so based on the constraints which currently we have none of based on the
constrains or some other program programming you know aspect of the of the application virtually place
this button and the moment that that decision is made for everyone.
This function essentially has been finished viewed did lay out of use.
So we talked about how viewable up here often happens right before transitioning to another view controller.
So if that is true.
So what happens to all the Wii controller the one that we just moved out of it so far that we have another
one called view did disappear and that is superb view disappear.
True.
So this function as you can imagine happens right then a view is disappearing from the stack and we
are moving to another view controller and it's a very useful place to get rid of continuous work for
instance or continuous tasks.
Finally have a default thing that is often called on the receive memory warming and that is superdog
did receive memory warning and if if this function happens it means that your memory has exceeded the
available memory of the device you're running on and you might want to do something about it if you
have a cache of so many images you might want to empty some of it or you might want to do something
that doesn't let your application crash.
To be honest this has never happened to me because most devices they have about four to eight gigabytes
of memory and is very difficult to kind of crush them.
So with that in mind let's go ahead and write a little print in each of these so we know where we are
as the as the fronts.
So I'm going to say print what they want to print.
The View will appear.
I'm going to put this one here say this is if you did disappear.
This is art.
Did you receive memory warning.
And I will show you a way to essentially simulate this.
So to force it to happen the you did lay out some views of fact and copy that.
Put it in here and say you did appear and that the default one which is view that last so I'm going
to copy that.
And view the notes of one's feet on the application.
We should be able to see all of these.
And then we're going to re format this code so that we know which one happens then because I want to
test the view did disappear.
I'm going to go to my main a storyboard.
I'm going to get rid of that segue and say My boss then takes me to the other view controller.
We're not doing anything and ping one for now.
So you only care about the green one.
So let's run this application.
And now that been loaded.
We have these four happening here.
That last view will appear view it lay on abuse and view it appear.
And these four are happening in the exact same order that we expected them to happen.
So if you go in here the first thing that's happening is that the view is loading.
So I'm going to put this one at the very top.
It doesn't really matter but just for the sake of presentation I'm doing this.
So the very first thing is that the view did load.
So every PC is now sitting next to each other and is properly allocated initialized.
The next thing is that the view will appear soon after that is the view is laying out the fuse.
So after you will appear at The View laid out the south views and then the view did appear which is
one.
So here
now the next thing is you want to see when does The View disappear happen.
And that is if I tap on this button and says view it disappear because we went into the ping fine so
that one is also successfully happening and to do the receive memory warning like I said is a feature
here that you can actually simulate that simulates memory warning.
And if you press that it says did receive memory warning you can actually add code in here that does
something beyond the memory warning happens.
Maybe like I said emptying the cash getting rid of some some data reading your values or whatever is
the way to do that.
So that's about the lifecycle of our of your controller.
I think this little text in here best describes it that it goes from view that low that allocates initializes
everything.
Then it goes to you will appear where everything is ready to be shown right before you contort is shown
and that you have to keep in mind is not necessarily about the second view controller and so on.
Even the very first controller has to be shown at some point at the beginning.
So a viewer will appear.
It happened right before then.
There is a lot then the subfields are being properly laid out based on the constrains for auto lay out
or their program and take values.
Once all of these things are ready the view will be in a state that it has appeared The View did appear
happens that's when you see things.
And then we go from one view to either one view disappears.
And of course you might get a memory warning.
So let's keep all of these in mind when we come to our apps.
We will be using these very important topic is you have to keep in mind that the view that load happens
once and that is when your view actually loads all of its objects but all the other ones happen multiple
times depending on your navigation between different view controllers and so on and so forth.
So let's keep that in mind on this.