1
00:00:00,290 --> 00:00:06,030
In business and we're going to see an actual delegation happening in a real US application what we are

2
00:00:06,030 --> 00:00:11,790
going to do is this we are going to go in Iowa with Tuvia controllers from what you can do or navigate

3
00:00:11,790 --> 00:00:13,710
to the next one in the next one.

4
00:00:13,710 --> 00:00:14,900
We will have a text field.

5
00:00:14,910 --> 00:00:20,910
We enter a value and we hit the back button but when we come back for the very first view controller

6
00:00:21,240 --> 00:00:26,670
we will see the masses we entered in the sack and The View Controller is essentially going to be a way

7
00:00:26,670 --> 00:00:32,230
for us to send a message from second to regular First the controller then the back.

8
00:00:32,230 --> 00:00:35,240
Why then is being pressed so let's see how are we going to do that.

9
00:00:35,250 --> 00:00:40,680
And when I go to school I'm going to start a new project this new project is going to be I was single

10
00:00:40,680 --> 00:00:44,980
view applications swift and I'm going to call it delegation.

11
00:00:45,000 --> 00:00:51,390
I guess I my delegation I was going to do some stuff that we already know how to do them like you know

12
00:00:51,420 --> 00:00:53,900
adding in new View Controller and everything.

13
00:00:53,910 --> 00:01:00,200
So let's say View Controller is our very first controller and I'm going to have myself a second view

14
00:01:00,210 --> 00:01:01,140
controller.

15
00:01:01,560 --> 00:01:08,970
I'm going to call this one our let's call it green view controller because I'm going to make it's by

16
00:01:08,970 --> 00:01:11,250
gone green obviously.

17
00:01:12,270 --> 00:01:19,740
So in the storyboard I have the default one which is essentially the The View control outlet.

18
00:01:19,890 --> 00:01:25,290
I'm going to have another one and this is a good time for us to you know repeat some of the older topics

19
00:01:25,290 --> 00:01:28,220
things that we covered in the previous sections.

20
00:01:28,230 --> 00:01:32,670
This is the one that's going to be green so I'm going to make it's going to become some sort of figurine

21
00:01:33,290 --> 00:01:36,210
and it's in that identity in a spectrum.

22
00:01:36,210 --> 00:01:38,820
But I call it to be the green View Controller.

23
00:01:38,850 --> 00:01:41,490
So so far we have to view controllers.

24
00:01:41,490 --> 00:01:46,260
I'm of course going to have a segue between this one too that one of the type Schull.

25
00:01:46,320 --> 00:01:49,700
Well I'm going to call this fun Green segue.

26
00:01:50,020 --> 00:01:53,370
Green segue Heidi.

27
00:01:53,660 --> 00:01:54,240
OK.

28
00:01:54,290 --> 00:01:56,010
So we've got all of these taken care of.

29
00:01:56,150 --> 00:02:00,090
Well next thing is I need a button to navigate to the green View Controller.

30
00:02:00,180 --> 00:02:07,860
So I'm going to add a button and this button since it's going to take us to the green one is going to

31
00:02:07,860 --> 00:02:08,990
be green.

32
00:02:09,390 --> 00:02:18,340
And it says in maybe Black says gold or green and I'm not going to make a Segway for it in here.

33
00:02:18,360 --> 00:02:20,550
We're going to make it programmatically.

34
00:02:20,550 --> 00:02:26,360
And I'm also going to have a label in here which is essentially the message that we receive.

35
00:02:26,580 --> 00:02:27,140
All right.

36
00:02:27,150 --> 00:02:31,190
So this one I'm going to say actually it's my gun.

37
00:02:31,230 --> 00:02:34,410
I'm going to leave it as dark grey by this text.

38
00:02:34,410 --> 00:02:38,740
I'm going to make it daring because this is the message we received from the other side.

39
00:02:38,970 --> 00:02:41,720
And currently it says message.

40
00:02:41,850 --> 00:02:43,890
Is there something that I want perfect.

41
00:02:43,920 --> 00:02:46,850
So we got that now in the other of your control.

42
00:02:46,900 --> 00:02:49,290
I'm going to have to have a pardon.

43
00:02:49,710 --> 00:02:51,450
And that's what it is up here.

44
00:02:51,450 --> 00:02:57,840
And that button says with a white background that is you know indicative of the view that is going to

45
00:02:57,840 --> 00:02:59,140
go back to.

46
00:02:59,310 --> 00:03:02,640
It says Go back and that's about that.

47
00:03:02,640 --> 00:03:09,400
It says Go back in black and then I have a text field that I can enter a value in it.

48
00:03:09,690 --> 00:03:14,590
So that's a text with my text which is a little bit larger than I like it without borders.

49
00:03:14,840 --> 00:03:17,420
I like it to be a little bit larger.

50
00:03:17,520 --> 00:03:18,850
I can say it's back.

51
00:03:18,870 --> 00:03:29,010
These are all very very light gray and text and it is there's a message perfect of what everything they

52
00:03:29,010 --> 00:03:31,090
need in terms of the outlets.

53
00:03:31,110 --> 00:03:37,960
Now I have to connect them to their respective of things in the coding area to the outlets as well as

54
00:03:38,050 --> 00:03:40,160
our actions.

55
00:03:40,230 --> 00:03:47,840
So in here on when our Lord my assistant editor I'm going to say for the first few controller I'm going

56
00:03:47,840 --> 00:03:50,490
to need these outlets I need.

57
00:03:50,520 --> 00:03:57,220
And an action that says action go to Green action.

58
00:03:57,260 --> 00:04:04,110
And I also need a label that says receive the message label.

59
00:04:04,290 --> 00:04:05,330
And that's about that.

60
00:04:05,340 --> 00:04:09,930
I've got the label and I got an action that I'm going to go to the other one to the green one and the

61
00:04:09,930 --> 00:04:13,500
green one and they have to do some cleanup.

62
00:04:13,560 --> 00:04:15,370
I'm going to do all of that right now.

63
00:04:15,480 --> 00:04:20,720
And in the green one I to have an A go back action.

64
00:04:20,730 --> 00:04:24,180
So that's going to be a go bag action.

65
00:04:24,180 --> 00:04:31,450
You know as always and I also have a text field that says not sage text.

66
00:04:31,740 --> 00:04:34,410
So I've got a text with a body action.

67
00:04:34,410 --> 00:04:35,820
Everything is ready.

68
00:04:35,880 --> 00:04:41,860
So now let's go ahead and see how we want to do how we can pass that on.

69
00:04:41,880 --> 00:04:48,990
The first thing I want to do is this every time that I press the button in they go to Green action.

70
00:04:48,990 --> 00:04:56,490
I want to say this I want to say self guard perform saying they identifier and here is the identifier

71
00:04:56,490 --> 00:04:59,730
that I need a thing I called it green.

72
00:04:59,960 --> 00:05:00,830
Identifier.

73
00:05:01,030 --> 00:05:01,500
Yes.

74
00:05:01,530 --> 00:05:03,200
Green segue.

75
00:05:03,430 --> 00:05:08,150
So that's the name for it green segue ID understand.

76
00:05:08,160 --> 00:05:09,560
Isn't it.

77
00:05:09,590 --> 00:05:15,140
Now here's one thing we did that when we go to the game in action we performed the Segway.

78
00:05:15,160 --> 00:05:19,880
If you recall we also have to prepare for that signee and he has hongbin do that.

79
00:05:19,900 --> 00:05:26,290
And when I say prepare for a Segway and in an ideal world if you want to be super careful about everything

80
00:05:26,590 --> 00:05:31,550
you have to say if Segway DOD identifier is blah blah blah.

81
00:05:31,660 --> 00:05:36,670
I don't really I'm not going to do that simply because I know I only have one Segway.

82
00:05:36,670 --> 00:05:43,750
So the only thing I'm going to do is that I'm going to say that I'm going to call it green in Staats

83
00:05:43,810 --> 00:05:46,940
is going to be sick of a destination.

84
00:05:47,200 --> 00:05:54,240
Now keep in mind the destination is a you view controller but they want it to be as green if you can

85
00:05:54,280 --> 00:05:54,490
it.

86
00:05:54,480 --> 00:05:56,480
I want it to be of this type.

87
00:05:56,680 --> 00:06:02,140
I want it to be forced as you know inferred as a green view controller.

88
00:06:02,140 --> 00:06:07,770
So so far be prepared even though we are not doing anything in here just yet and we perform the same

89
00:06:07,760 --> 00:06:08,090
way.

90
00:06:08,230 --> 00:06:11,440
Let's see what we see in the green view controller in here.

91
00:06:11,440 --> 00:06:17,260
We have a text field in here that we haven't done anything and we have a function that takes us back.

92
00:06:17,380 --> 00:06:24,700
This first thing with the function that takes us about it says self that this is true and that's about

93
00:06:24,700 --> 00:06:24,930
that.

94
00:06:24,940 --> 00:06:27,330
And don't do anything at completion.

95
00:06:27,370 --> 00:06:33,690
So that's one part of it and another thing I'm going to do is I'm going to say let's text to send.

96
00:06:33,770 --> 00:06:38,980
Is going to be message text field that dot text.

97
00:06:38,980 --> 00:06:41,580
So let's get the text in the message text.

98
00:06:41,590 --> 00:06:43,680
We don't we have to do something with it.

99
00:06:43,690 --> 00:06:46,110
We have to do something.

100
00:06:46,150 --> 00:06:48,410
I just don't know what that thing is.

101
00:06:48,610 --> 00:06:53,050
So if all goes well by now we should be able to navigate back and forth.

102
00:06:53,050 --> 00:06:58,920
So let's go ahead and run this application even though some variables are not being used just yet they're

103
00:06:58,930 --> 00:07:04,180
just sitting there on their own for not doing anything with them but this application essentially does

104
00:07:04,180 --> 00:07:09,010
work and takes us from one of your contorted to the other one where there is a text field that we can

105
00:07:09,010 --> 00:07:11,820
enter values and where we can hit the back within.

106
00:07:11,880 --> 00:07:17,440
But obviously nothing gets communicated between our two controllers.

107
00:07:17,500 --> 00:07:26,390
So once I have my eye out I'm going to call this file to be a protocol create I know I have this protocol

108
00:07:26,420 --> 00:07:35,500
that I'm going to say it is actually a protocol it's called sending a message delegates and that's about

109
00:07:35,510 --> 00:07:45,830
that it of one method called function send me which essentially gets a message of to tie a string and

110
00:07:45,830 --> 00:07:47,980
that's about that's all it does.

111
00:07:48,260 --> 00:07:56,990
So here in my view control the very first view controller I'm going to say this class view controller

112
00:07:56,990 --> 00:08:03,590
conforms to you eye view controller and also sending the message delegate.

113
00:08:03,620 --> 00:08:05,560
So it conforms to both of them.

114
00:08:05,570 --> 00:08:11,390
And now you get an error saying well if you want to conform to this you also have to give it that method

115
00:08:11,450 --> 00:08:12,820
that method is called.

116
00:08:13,010 --> 00:08:15,610
I forgot this cause I'm just going to add it in here.

117
00:08:15,800 --> 00:08:17,580
It says send a message.

118
00:08:17,580 --> 00:08:20,060
So it has to conform to this one.

119
00:08:20,060 --> 00:08:26,190
So what do you want to do whenever this function happens will come to this in a second.

120
00:08:26,240 --> 00:08:31,370
The other thing I want to do is this I want to go to my grave you can sort of just like the last time

121
00:08:31,730 --> 00:08:34,280
this is the guy who is going to be our sender.

122
00:08:34,460 --> 00:08:39,710
If you remember from our previous example this was for instance or a user.

123
00:08:39,810 --> 00:08:49,820
So I'm going to say well I have a valuable I'm going to call it the elegant which is of the type sending

124
00:08:49,820 --> 00:08:51,370
the message delegate.

125
00:08:51,410 --> 00:08:55,600
So I have this variable in green view controllers.

126
00:08:55,670 --> 00:08:59,990
So what do you want to do you want them to do this will they want them to do.

127
00:08:59,990 --> 00:09:08,570
When I pressed the go back action I want my delegate to call its message and I want to send this particular

128
00:09:08,570 --> 00:09:11,420
message text to send.

129
00:09:11,420 --> 00:09:15,650
So that's the text that I want to send through the delicate matter.

130
00:09:15,710 --> 00:09:17,600
Now who is going to receive this.

131
00:09:17,600 --> 00:09:20,510
On the other end The View Controller.

132
00:09:20,510 --> 00:09:22,560
This function has to receive it.

133
00:09:22,610 --> 00:09:24,560
What should it do was it received it.

134
00:09:24,680 --> 00:09:31,430
It has to put it in the received message Nevel the text as to be become message.

135
00:09:31,430 --> 00:09:39,920
Now there is one piece still missing and that is this function works well if we reset giving a message

136
00:09:39,950 --> 00:09:41,580
it puts it in our label.

137
00:09:41,930 --> 00:09:43,450
This one works well.

138
00:09:43,460 --> 00:09:46,530
It sends it to its delegate's.

139
00:09:46,580 --> 00:09:53,630
The only thing we don't know is the green view controller is delegating his tasks to which object.

140
00:09:53,690 --> 00:09:55,830
And that's something they haven't done yet.

141
00:09:55,850 --> 00:10:03,320
So if I go to my view controller and in here I'm gonna say green stance

142
00:10:05,720 --> 00:10:09,680
that delegate is going to be self.

143
00:10:09,830 --> 00:10:16,550
What it means is this it means the green stance is going to deligated tasks all of its tasks to self

144
00:10:17,030 --> 00:10:22,460
which is the view controller which does conform to send the message delegate.

145
00:10:22,460 --> 00:10:31,150
Which means if the any green stands delegate's its particular function call to send this class viewer

146
00:10:31,150 --> 00:10:32,020
response.

147
00:10:32,270 --> 00:10:40,550
So when the game view controller says in case you were going back there to get that send this message

148
00:10:40,910 --> 00:10:46,580
the one who is going to actually receive this message is going to be our view controller.

149
00:10:46,650 --> 00:10:52,240
This is because our warning is because we didn't change anything and well turn that into a constant

150
00:10:52,430 --> 00:10:56,630
and let's run our application one more time and see what do we get.

151
00:10:57,200 --> 00:11:07,760
And here's my simulator and I have go to Green and saying hello white go back I says hello once I go

152
00:11:07,760 --> 00:11:08,640
in here.

153
00:11:08,780 --> 00:11:13,980
I say Are you a fool sky.

154
00:11:14,010 --> 00:11:15,620
I don't know why I came up with that.

155
00:11:15,650 --> 00:11:17,720
I go back and it says beautiful sky.

156
00:11:17,720 --> 00:11:19,950
It sends a message to the other side.

157
00:11:20,210 --> 00:11:25,430
Let me quickly recap things that they made a big chunk of it doesn't really matter.

158
00:11:25,430 --> 00:11:31,750
So our view controller has a label has an action none of them Mandos performs a Segway.

159
00:11:31,750 --> 00:11:32,810
We know how that works.

160
00:11:32,810 --> 00:11:34,180
This part is a new thing.

161
00:11:34,190 --> 00:11:35,680
Prepare for Segway.

162
00:11:35,690 --> 00:11:43,210
It says get the Segway destination as Glenview controller and set its delegates to be here.

163
00:11:43,340 --> 00:11:50,560
Now Grangeville a controller has a delegate valuable in it which is of the type sending message delegate

164
00:11:51,020 --> 00:12:00,110
and seen sending message delegate also has that particular function whenever we call that one delegate

165
00:12:00,110 --> 00:12:05,450
to send somebody would be on the other side trying to receive these.

166
00:12:05,600 --> 00:12:12,380
In this case that it has to be the view controller the sky which does not conform to sending message

167
00:12:12,390 --> 00:12:14,900
and get either receives that one.

168
00:12:14,930 --> 00:12:15,950
So that's about that.

169
00:12:15,950 --> 00:12:21,590
We managed to successfully communicate between two objects of our differing classes.

170
00:12:21,590 --> 00:12:28,660
One of them conforming the other one using delegate valuable and let's move on doing the same thing

171
00:12:28,690 --> 00:12:32,930
once again as an exercise I will also do it at the end.

172
00:12:33,070 --> 00:12:33,960
In Objective-C.
