1
00:00:00,940 --> 00:00:05,670
In your system you can talk about the life cycles that we have in view control.

2
00:00:05,700 --> 00:00:11,850
There are many many different life cycles and they essentially define how a viewpoint or a goes through

3
00:00:11,850 --> 00:00:13,460
its different stages.

4
00:00:13,470 --> 00:00:17,390
So this is I will try to explain as many of them as I can for you.

5
00:00:17,580 --> 00:00:18,870
The school two weeks.

6
00:00:18,990 --> 00:00:26,450
And I'm going to make a new application let's call this one our view control are View.

7
00:00:26,580 --> 00:00:38,530
That's right the whole thing View control life cycle is so like that it's and I'm sure by now you have

8
00:00:38,530 --> 00:00:45,390
definitely seen or have used the view that the law is the default thing that we always have in here.

9
00:00:45,490 --> 00:00:50,230
Now beyond that there are so many many other wants and what I'm good at doing this lesson is I'm right

10
00:00:50,260 --> 00:00:51,390
all of them down.

11
00:00:51,610 --> 00:00:57,010
And then we're going to go ahead and print something in each of them to find out which one comes first

12
00:00:57,400 --> 00:01:01,400
and then they're going to reorder them so we get a sense of what's happening.

13
00:01:01,690 --> 00:01:06,640
So another one is actually called viu will appear.

14
00:01:07,030 --> 00:01:14,770
So the mule will appear and that is super dart of view will appear because it's a subclass of the few

15
00:01:14,770 --> 00:01:16,140
control of course.

16
00:01:16,390 --> 00:01:18,400
So let's see what you will appear does.

17
00:01:18,400 --> 00:01:24,700
And what's the difference between the ones that they say view something something load or view something

18
00:01:24,760 --> 00:01:25,860
and appears.

19
00:01:25,990 --> 00:01:32,590
The difference between these two is this Indos view is low that essentially it means all of your objects

20
00:01:32,590 --> 00:01:39,550
are created but they are not visible to user or they're not going to be visible just yet in the ones

21
00:01:39,550 --> 00:01:43,090
that they say View will appear or view did appear.

22
00:01:43,090 --> 00:01:49,460
It means that something is going to be visible or something has become visible some little right in

23
00:01:49,460 --> 00:01:51,010
here.

24
00:01:51,190 --> 00:01:54,650
You will soon be shown.

25
00:01:55,330 --> 00:02:07,090
And this is often useful for are useful for van right before transitioning into another view controller.

26
00:02:07,110 --> 00:02:12,700
This would be very useful for the moment that you're going to another view control and you want to have

27
00:02:12,700 --> 00:02:19,420
something happening and other lifecycle that we have in here is viewed with a Ph.

28
00:02:19,440 --> 00:02:22,520
And obviously the name of it is suggesting what it does.

29
00:02:22,520 --> 00:02:30,160
This is essentially for in your view has loaded all the objects are initialized and now it is being

30
00:02:30,160 --> 00:02:32,610
shown on the screen to your user.

31
00:02:32,770 --> 00:02:36,680
So you might be wondering what's the difference between viewed it appear and view lot.

32
00:02:36,700 --> 00:02:38,990
And what should I use in view that appear.

33
00:02:39,190 --> 00:02:46,180
So when you look at the new law essentially everything that you want has been initialized and allocated

34
00:02:46,210 --> 00:02:48,060
but they are not being visible yet.

35
00:02:48,070 --> 00:02:53,500
And there might be a little time between that and when they are being you know visible.

36
00:02:53,500 --> 00:03:00,390
So for instance if you want to start a timer start a timer or run an animation.

37
00:03:00,400 --> 00:03:07,470
This would be a much better place because there it will happen once things are being shown on the screen.

38
00:03:07,630 --> 00:03:12,640
Now in saying that there is a little bit of a downside and something that you have to be careful about

39
00:03:13,490 --> 00:03:20,140
what happens just once only once in the life cycle of your application.

40
00:03:20,140 --> 00:03:27,010
So if you load an app and you go from one view control to either one that only happens the very first

41
00:03:27,010 --> 00:03:32,760
time you're going to that view control both views that appear happens every time that that you counter

42
00:03:32,860 --> 00:03:34,270
is being shown.

43
00:03:34,270 --> 00:03:36,640
So if I go to my storyboard

44
00:03:39,200 --> 00:03:47,660
and imagine I have this main view controller that has a background with a color such as says I have

45
00:03:47,660 --> 00:03:50,840
a new installation of exclude all my colors are gone.

46
00:03:50,840 --> 00:03:55,960
So I have to remake them so they have this fun with some sort of a green background.

47
00:03:56,030 --> 00:04:03,490
And I have another view controller on this one I'm going to maybe make it a little bit pink.

48
00:04:04,370 --> 00:04:05,180
OK.

49
00:04:05,610 --> 00:04:11,430
So this is my other one.

50
00:04:11,500 --> 00:04:15,950
So the moment the app runs this view is going to be loaded.

51
00:04:15,950 --> 00:04:18,980
And that's the last time that that cycle happens.

52
00:04:19,190 --> 00:04:25,830
And then when I have a Segway and I go to the other one whenever I go to the ping point of view loads.

53
00:04:25,910 --> 00:04:32,300
Now if I had a button to go back when I come back to the green one it is not viewed that load anymore.

54
00:04:32,330 --> 00:04:37,120
It is the view it appears that happens over and over and over.

55
00:04:37,130 --> 00:04:41,150
So keep in mind that the view that happens only once.

56
00:04:41,150 --> 00:04:42,950
Why would it appear.

57
00:04:43,370 --> 00:04:50,770
Happens each time that you are land in this view controller.

58
00:04:50,960 --> 00:04:57,170
So that's something that you have to keep in mind because sometimes you know you shouldn't try to initialize

59
00:04:57,170 --> 00:05:02,870
or allocate something in the view that appear simply because we run multiple times.

60
00:05:02,870 --> 00:05:10,130
If you do that now as you can imagine view you appear simply happens after view will appear.

61
00:05:10,340 --> 00:05:15,490
And there's another one that happened somehow between these two or somewhere between these two.

62
00:05:15,740 --> 00:05:18,530
And that is the one that they call view tape.

63
00:05:18,610 --> 00:05:20,600
Lay out some views.

64
00:05:20,840 --> 00:05:25,220
So this is superdad view that lay out some views.

65
00:05:25,320 --> 00:05:32,090
This is essentially where all the pieces of the view are laid out and what laying out means is something

66
00:05:32,090 --> 00:05:37,880
that they're going to talk about it a lot in the coming lessons in Arthur lay out but essentially means

67
00:05:37,880 --> 00:05:47,020
this if you have an idea let's go ahead and say by then and this button is meant to be in this particular

68
00:05:47,020 --> 00:05:50,900
place with a bad going for it I can see it.

69
00:05:51,490 --> 00:05:57,430
And this is not currently being designed for iPhone 8 and you're running your app on let's say iPhone

70
00:05:57,430 --> 00:05:58,090
X..

71
00:05:58,240 --> 00:06:02,460
So what should it do and where should it be laid out.

72
00:06:02,500 --> 00:06:04,370
So someone else will decide about that.

73
00:06:04,390 --> 00:06:07,080
And that is this lifecycle.

74
00:06:07,090 --> 00:06:13,720
This is the one that this is so based on the constraints which currently we have none of based on the

75
00:06:13,760 --> 00:06:20,590
constrains or some other program programming you know aspect of the of the application virtually place

76
00:06:20,590 --> 00:06:25,090
this button and the moment that that decision is made for everyone.

77
00:06:25,200 --> 00:06:31,270
This function essentially has been finished viewed did lay out of use.

78
00:06:31,420 --> 00:06:38,680
So we talked about how viewable up here often happens right before transitioning to another view controller.

79
00:06:38,860 --> 00:06:40,450
So if that is true.

80
00:06:40,540 --> 00:06:47,920
So what happens to all the Wii controller the one that we just moved out of it so far that we have another

81
00:06:47,920 --> 00:06:54,820
one called view did disappear and that is superb view disappear.

82
00:06:55,860 --> 00:06:56,740
True.

83
00:06:57,010 --> 00:07:03,990
So this function as you can imagine happens right then a view is disappearing from the stack and we

84
00:07:03,990 --> 00:07:11,410
are moving to another view controller and it's a very useful place to get rid of continuous work for

85
00:07:11,410 --> 00:07:14,100
instance or continuous tasks.

86
00:07:15,680 --> 00:07:26,120
Finally have a default thing that is often called on the receive memory warming and that is superdog

87
00:07:26,240 --> 00:07:32,960
did receive memory warning and if if this function happens it means that your memory has exceeded the

88
00:07:32,960 --> 00:07:37,940
available memory of the device you're running on and you might want to do something about it if you

89
00:07:37,940 --> 00:07:44,570
have a cache of so many images you might want to empty some of it or you might want to do something

90
00:07:44,570 --> 00:07:47,070
that doesn't let your application crash.

91
00:07:47,210 --> 00:07:53,060
To be honest this has never happened to me because most devices they have about four to eight gigabytes

92
00:07:53,060 --> 00:07:57,470
of memory and is very difficult to kind of crush them.

93
00:07:57,500 --> 00:08:03,710
So with that in mind let's go ahead and write a little print in each of these so we know where we are

94
00:08:03,740 --> 00:08:06,070
as the as the fronts.

95
00:08:06,090 --> 00:08:09,050
So I'm going to say print what they want to print.

96
00:08:09,060 --> 00:08:11,420
The View will appear.

97
00:08:11,750 --> 00:08:18,480
I'm going to put this one here say this is if you did disappear.

98
00:08:18,860 --> 00:08:22,050
This is art.

99
00:08:22,070 --> 00:08:24,430
Did you receive memory warning.

100
00:08:24,560 --> 00:08:27,930
And I will show you a way to essentially simulate this.

101
00:08:27,950 --> 00:08:37,190
So to force it to happen the you did lay out some views of fact and copy that.

102
00:08:37,190 --> 00:08:46,530
Put it in here and say you did appear and that the default one which is view that last so I'm going

103
00:08:46,550 --> 00:08:47,760
to copy that.

104
00:08:47,910 --> 00:08:50,550
And view the notes of one's feet on the application.

105
00:08:50,550 --> 00:08:52,100
We should be able to see all of these.

106
00:08:52,110 --> 00:08:58,530
And then we're going to re format this code so that we know which one happens then because I want to

107
00:08:58,530 --> 00:09:00,650
test the view did disappear.

108
00:09:00,690 --> 00:09:02,810
I'm going to go to my main a storyboard.

109
00:09:03,150 --> 00:09:08,600
I'm going to get rid of that segue and say My boss then takes me to the other view controller.

110
00:09:08,640 --> 00:09:11,610
We're not doing anything and ping one for now.

111
00:09:11,610 --> 00:09:13,810
So you only care about the green one.

112
00:09:14,070 --> 00:09:17,040
So let's run this application.

113
00:09:17,200 --> 00:09:18,800
And now that been loaded.

114
00:09:18,850 --> 00:09:22,010
We have these four happening here.

115
00:09:22,220 --> 00:09:29,420
That last view will appear view it lay on abuse and view it appear.

116
00:09:29,500 --> 00:09:34,480
And these four are happening in the exact same order that we expected them to happen.

117
00:09:34,720 --> 00:09:39,120
So if you go in here the first thing that's happening is that the view is loading.

118
00:09:39,120 --> 00:09:41,940
So I'm going to put this one at the very top.

119
00:09:42,010 --> 00:09:46,750
It doesn't really matter but just for the sake of presentation I'm doing this.

120
00:09:46,750 --> 00:09:49,300
So the very first thing is that the view did load.

121
00:09:49,300 --> 00:09:54,910
So every PC is now sitting next to each other and is properly allocated initialized.

122
00:09:54,940 --> 00:10:03,220
The next thing is that the view will appear soon after that is the view is laying out the fuse.

123
00:10:03,310 --> 00:10:10,760
So after you will appear at The View laid out the south views and then the view did appear which is

124
00:10:11,080 --> 00:10:12,850
one.

125
00:10:12,880 --> 00:10:13,440
So here

126
00:10:16,960 --> 00:10:21,300
now the next thing is you want to see when does The View disappear happen.

127
00:10:21,310 --> 00:10:28,930
And that is if I tap on this button and says view it disappear because we went into the ping fine so

128
00:10:29,020 --> 00:10:35,870
that one is also successfully happening and to do the receive memory warning like I said is a feature

129
00:10:36,010 --> 00:10:40,960
here that you can actually simulate that simulates memory warning.

130
00:10:41,170 --> 00:10:46,810
And if you press that it says did receive memory warning you can actually add code in here that does

131
00:10:46,900 --> 00:10:49,690
something beyond the memory warning happens.

132
00:10:49,690 --> 00:10:56,170
Maybe like I said emptying the cash getting rid of some some data reading your values or whatever is

133
00:10:56,170 --> 00:10:57,760
the way to do that.

134
00:10:58,060 --> 00:11:02,670
So that's about the lifecycle of our of your controller.

135
00:11:02,830 --> 00:11:09,870
I think this little text in here best describes it that it goes from view that low that allocates initializes

136
00:11:09,910 --> 00:11:10,640
everything.

137
00:11:10,750 --> 00:11:17,290
Then it goes to you will appear where everything is ready to be shown right before you contort is shown

138
00:11:17,680 --> 00:11:23,800
and that you have to keep in mind is not necessarily about the second view controller and so on.

139
00:11:23,890 --> 00:11:28,840
Even the very first controller has to be shown at some point at the beginning.

140
00:11:28,870 --> 00:11:30,000
So a viewer will appear.

141
00:11:30,010 --> 00:11:31,910
It happened right before then.

142
00:11:32,020 --> 00:11:38,050
There is a lot then the subfields are being properly laid out based on the constrains for auto lay out

143
00:11:38,080 --> 00:11:40,450
or their program and take values.

144
00:11:40,530 --> 00:11:46,990
Once all of these things are ready the view will be in a state that it has appeared The View did appear

145
00:11:46,990 --> 00:11:49,300
happens that's when you see things.

146
00:11:49,480 --> 00:11:53,860
And then we go from one view to either one view disappears.

147
00:11:53,920 --> 00:11:56,730
And of course you might get a memory warning.

148
00:11:56,950 --> 00:12:01,380
So let's keep all of these in mind when we come to our apps.

149
00:12:01,450 --> 00:12:07,090
We will be using these very important topic is you have to keep in mind that the view that load happens

150
00:12:07,180 --> 00:12:14,230
once and that is when your view actually loads all of its objects but all the other ones happen multiple

151
00:12:14,230 --> 00:12:20,510
times depending on your navigation between different view controllers and so on and so forth.

152
00:12:20,770 --> 00:12:22,740
So let's keep that in mind on this.
