1
00:00:00,540 --> 00:00:04,620
So far we had a look at some of the delegation that we developed ourselves.

2
00:00:04,650 --> 00:00:06,320
So we wrote our own protocols.

3
00:00:06,340 --> 00:00:10,860
We conformed the class to that and then we use that to pass a message.

4
00:00:10,860 --> 00:00:15,990
Now in this lesson we're going to look at some of the delegations that exist in different classes in

5
00:00:15,990 --> 00:00:21,630
the U.S. almost every class in the U.S. has at least one delegation and then some of them they have

6
00:00:21,630 --> 00:00:22,960
a lot more than that.

7
00:00:23,160 --> 00:00:29,190
So let's have a look at doors in export and what looks good on that to start a new project.

8
00:00:29,410 --> 00:00:34,970
Iowas application that is actually a good time for us to take what we learned into an actual application

9
00:00:35,520 --> 00:00:37,240
not a single view of un-Godly.

10
00:00:37,260 --> 00:00:46,350
That's why if I'm going to say text field the allegations are swift end in here I'm going to go ahead

11
00:00:46,350 --> 00:00:47,990
and say my a storyboard.

12
00:00:48,000 --> 00:00:52,530
I have one text that's the only thing that they want to have in here.

13
00:00:52,620 --> 00:00:58,860
Here's a text that I'm actually going to go ahead to the same thing as usual no borders.

14
00:00:58,980 --> 00:01:04,910
Make sure the background is something that you can actually view it and that takes a little bit larger

15
00:01:04,920 --> 00:01:10,710
have a placeholder saying for instance a value line at the site and all of these things and all you

16
00:01:10,710 --> 00:01:14,150
can do within your own whatever you feel like more comfortable.

17
00:01:14,580 --> 00:01:18,750
So the next thing is I'm going to have to make an outlet for my text.

18
00:01:18,870 --> 00:01:20,410
So same thing as before.

19
00:01:20,460 --> 00:01:29,860
ASSISTANT EDITOR IN MY a class like this one and call it my text file.

20
00:01:30,300 --> 00:01:33,160
So so far we haven't done anything that is different.

21
00:01:33,180 --> 00:01:35,100
We have made a text field and get that.

22
00:01:35,140 --> 00:01:41,880
And now I know one you will know soon as well that most outlets in your interface builder they have

23
00:01:41,880 --> 00:01:47,540
built in delegates and you can call those delegates by doing either of these two things.

24
00:01:47,730 --> 00:01:53,970
Either hold the control button and drag them over your view controller in the window that pops you could

25
00:01:53,970 --> 00:02:01,400
say outlet delegate's which means I'm delegating from my text field to this view controller.

26
00:02:01,530 --> 00:02:03,080
So let's do that.

27
00:02:03,180 --> 00:02:06,100
Or you could actually do it through the programming.

28
00:02:06,120 --> 00:02:09,150
I'm going to do it in both sides so we see both of them.

29
00:02:09,270 --> 00:02:15,510
So the first one was holding control and dragging over our view controller and saying delegates that's

30
00:02:15,510 --> 00:02:16,570
one way of doing it.

31
00:02:16,590 --> 00:02:23,020
I'm actually going to go ahead and disconnect it so I can do it one more way the other way was this

32
00:02:23,140 --> 00:02:28,780
way I go to my view controller and in my view controller I'm going to clean everything up like usual.

33
00:02:29,240 --> 00:02:35,490
And in my view that law the moment of you know what I'm going to say my text with that daily guest becomes

34
00:02:35,570 --> 00:02:38,300
stuff becomes this one.

35
00:02:38,310 --> 00:02:45,390
Now if you recall anyone that we wanted to assign that delegate to it had to conform to that delegation

36
00:02:45,390 --> 00:02:51,640
protocol which I'm currently not doing that so I'm going to go to my class viewer controller.

37
00:02:51,730 --> 00:02:58,980
So for a class you I view controller and I'm going to say you find a text field that delegate's so and

38
00:02:59,040 --> 00:03:02,520
conforming to you why feel delegate as well.

39
00:03:02,640 --> 00:03:08,520
So now my view controller can accept delegation methods from my textbook.

40
00:03:08,800 --> 00:03:14,040
But what are those what are the different functions or properties that we can use from the sky.

41
00:03:14,100 --> 00:03:15,630
Let's go ahead and google it up.

42
00:03:15,630 --> 00:03:17,150
I'm going to go to my browser.

43
00:03:17,150 --> 00:03:24,160
Say Give me your text textfield delegates and go look at the text with delegate and soon enough we will

44
00:03:24,160 --> 00:03:26,470
learn better ways of finding this matters.

45
00:03:26,490 --> 00:03:28,710
But for now I'm going to find those.

46
00:03:28,830 --> 00:03:36,630
I see that in the delegation you know everything is stuff I have textfield should begin editing takes

47
00:03:36,630 --> 00:03:38,540
with did begin editing.

48
00:03:38,540 --> 00:03:44,730
So this one gets triggered the moment you start entering a value or it says the one I'm looking for

49
00:03:44,730 --> 00:03:47,510
actually is something called text which should return.

50
00:03:47,550 --> 00:03:53,610
Let's read that up and it says Ask the delegate if that takes which should process the processing of

51
00:03:53,610 --> 00:03:55,040
the return button.

52
00:03:55,230 --> 00:04:00,510
So weatherman we had ridden by then something should happen or not and I'm going we use that.

53
00:04:00,510 --> 00:04:04,690
So it is called textfield should return the squarehead scope.

54
00:04:04,860 --> 00:04:10,590
And as long as you are programming in Swiftie can just type a little part of that code and will automatically

55
00:04:10,710 --> 00:04:12,210
auto complete it for you.

56
00:04:12,350 --> 00:04:15,060
So I'm going to say textfield Should that.

57
00:04:15,300 --> 00:04:16,790
And it says or should return.

58
00:04:16,800 --> 00:04:18,550
Is that the one you're looking for.

59
00:04:18,640 --> 00:04:21,300
And as you can see the return if it is a boolean.

60
00:04:21,360 --> 00:04:24,510
So I'm going to say return true.

61
00:04:24,690 --> 00:04:28,490
So yes it has to do something but what should it do.

62
00:04:28,530 --> 00:04:34,220
So let's go ahead and quickly talk about that a very very simple case of this would be this.

63
00:04:34,350 --> 00:04:39,750
I'm going to go to a storyboard and I'm going to select my text and when a change return returned then

64
00:04:40,070 --> 00:04:42,520
to look like a done by then.

65
00:04:42,720 --> 00:04:47,610
Even though this isn't really necessary I like to do it so it kind of becomes more clear what you're

66
00:04:47,640 --> 00:04:48,140
doing.

67
00:04:48,300 --> 00:04:55,290
So a return key is a donkey and I'm going to say the moment that textfield should return function is

68
00:04:55,290 --> 00:04:58,260
a trigger before you return true.

69
00:04:58,620 --> 00:05:03,020
Do this textfield resign the first responder.

70
00:05:03,240 --> 00:05:06,110
And I'm sure you can guess what this is going to do for us.

71
00:05:06,130 --> 00:05:11,760
Is it going to essentially say every time you press the return button on this textfield get rid of the

72
00:05:11,760 --> 00:05:15,480
keyboard and then yes that should happen.

73
00:05:15,540 --> 00:05:16,930
So I'm going to go in here.

74
00:05:17,100 --> 00:05:18,620
I'm going to.

75
00:05:18,810 --> 00:05:22,050
Show me the keyboard by pressing on the screen.

76
00:05:22,320 --> 00:05:26,740
And if you don't see the keyboard is because your soft keyboard is not on.

77
00:05:26,760 --> 00:05:29,090
You have to go in here on Press command OK.

78
00:05:29,150 --> 00:05:32,490
So if I have command Cain here the keyboard disappears.

79
00:05:32,490 --> 00:05:37,710
If I had command again it appears and testing purposes doesn't really matter but when you're using the

80
00:05:37,710 --> 00:05:40,890
simulator keep in mind keyboard shows up here.

81
00:05:40,900 --> 00:05:48,930
So I'm going to say let's say high on had done and gets rid of the keyboard now you might be asking

82
00:05:48,930 --> 00:05:56,760
yourself so what is this text field argument that is in here that essentially calls that text field

83
00:05:56,880 --> 00:05:59,440
that has triggered this function.

84
00:05:59,550 --> 00:06:05,740
You can simply imagine that this may not be the only text field that you have in your interface.

85
00:06:05,820 --> 00:06:12,180
You might have two of those and then depending on which one is doing something you might want to do

86
00:06:12,180 --> 00:06:14,430
a different thing in the next example.

87
00:06:14,590 --> 00:06:15,860
I'm actually going to do that.

88
00:06:15,900 --> 00:06:23,000
I'm going to go ahead in here I'm going to use a different delegate function called Text field.

89
00:06:23,220 --> 00:06:31,790
Should change should change which is this which essentially says Should I change the value that you

90
00:06:31,790 --> 00:06:34,450
are typing in a text field or not.

91
00:06:34,450 --> 00:06:38,190
Now let me quickly explain what is this useful for.

92
00:06:38,190 --> 00:06:45,030
Imagine a situation like this and we saw this sometime in the past that we wanted to have a text field

93
00:06:45,060 --> 00:06:47,900
that we can only enter numeric values.

94
00:06:47,940 --> 00:06:52,950
So two three to four would be valid values but effort would end.

95
00:06:53,190 --> 00:06:59,850
So we can actually use this function textfield should to change Kerak there to decide whether it should

96
00:06:59,850 --> 00:07:01,110
actually change or not.

97
00:07:01,110 --> 00:07:05,630
So practically by the end of this exercise we should be able to do this.

98
00:07:05,820 --> 00:07:09,130
If I were going here I'm press tree that should appear.

99
00:07:09,300 --> 00:07:15,680
But the 5:01 press pass that shouldn't appeal it should just be returned as a false value.

100
00:07:15,690 --> 00:07:17,190
So let's see how I'm going to do that.

101
00:07:17,190 --> 00:07:23,040
The first thing I'm going to do is I'm going to get myself a little bit more space and then I'm going

102
00:07:23,040 --> 00:07:26,260
to go ahead and say this is the logic that I want to do.

103
00:07:26,280 --> 00:07:27,770
The logic is this.

104
00:07:28,050 --> 00:07:32,880
Let's get all non numeric values.

105
00:07:33,150 --> 00:07:42,640
So these are things such as a s b c the com dot dot I all the star and whatever.

106
00:07:42,660 --> 00:07:47,740
Anything that is non numeric value that you can use get by a keyboard.

107
00:07:48,060 --> 00:07:52,800
Then I'm going to say let's get our string this string.

108
00:07:52,800 --> 00:07:57,150
We are trying to enter and divide that by these guys.

109
00:07:57,150 --> 00:07:58,090
What does that mean.

110
00:07:58,200 --> 00:08:00,530
Let's say a string is this.

111
00:08:00,540 --> 00:08:01,760
Those are the numbers.

112
00:08:01,960 --> 00:08:06,070
And then H-G some random characters and then those numbers.

113
00:08:06,300 --> 00:08:14,330
All right if I go ahead and divide that this string by the characters that are here then non-numeric

114
00:08:14,370 --> 00:08:17,660
characters we call that one card.

115
00:08:18,000 --> 00:08:26,370
If I divide it by non-numeric character I have this I will have the first part which is that I'm dividing

116
00:08:26,380 --> 00:08:30,540
by disguise etch j u s f d g.

117
00:08:30,750 --> 00:08:34,010
And if I had one more you know percentage in here.

118
00:08:34,080 --> 00:08:42,810
So that would be the first part and then I would have the next part which is four five six which is

119
00:08:42,810 --> 00:08:47,100
that and that I would have that last part which is a 78.

120
00:08:47,160 --> 00:08:55,220
So if I break my text against these dividers then non-numeric characters I will end up with this.

121
00:08:55,370 --> 00:09:01,020
The next thing I'm going to do is I'm going to say let's join all of these things together which becomes

122
00:09:01,550 --> 00:09:03,200
our previous pasted there.

123
00:09:03,480 --> 00:09:09,510
All of them together then I'm going to say compared the original text.

124
00:09:09,720 --> 00:09:13,430
This one against this new one.

125
00:09:13,980 --> 00:09:19,100
If they all the same it means I didn't have any non-numeric character.

126
00:09:19,110 --> 00:09:21,030
It means everything was numeric.

127
00:09:21,210 --> 00:09:26,430
But if they are not the same it means that something has gone wrong and I have an unusually quiet you

128
00:09:26,430 --> 00:09:28,350
and I should return true.

129
00:09:28,500 --> 00:09:30,820
So that's the logic of what I want to do.

130
00:09:30,840 --> 00:09:33,910
Let's go ahead and actually do the the first thing I'm going to do is this.

131
00:09:33,990 --> 00:09:37,500
I'm going to say let's call it numbers.

132
00:09:37,500 --> 00:09:44,430
Becomes are all of these guys which is very simple so we first get all the numbers all the things that

133
00:09:44,490 --> 00:09:46,150
we wouldn't like to have.

134
00:09:46,230 --> 00:09:46,950
Right.

135
00:09:47,070 --> 00:09:50,500
Then the next thing is I'm going to say let's let's call it.

136
00:09:50,660 --> 00:09:55,090
Remove the heart set.

137
00:09:55,150 --> 00:09:59,190
So this is the characters that I would like to remove and that's going to be on.

138
00:09:59,240 --> 00:10:05,470
And this character sets the targeteers in numbers.

139
00:10:06,270 --> 00:10:12,570
So that is my character set but this is the actual character set of the numbers not the ones I want

140
00:10:12,570 --> 00:10:13,620
to remove.

141
00:10:13,800 --> 00:10:16,620
So because I want to remove them I'm going to say well you know what.

142
00:10:16,680 --> 00:10:20,680
Get these guys and then do what we call inverted.

143
00:10:20,910 --> 00:10:22,040
So reverse it.

144
00:10:22,080 --> 00:10:28,080
Get these guys and then find everyone who is not to these guys because I could go ahead and manually

145
00:10:28,080 --> 00:10:32,070
try to type those but it would be a very very long set of characters.

146
00:10:32,070 --> 00:10:35,060
It would be a b c d e f g Hosh.

147
00:10:35,130 --> 00:10:42,770
All the way to Z and then the capital letters of all of these things and then every value that is non-numeric

148
00:10:42,870 --> 00:10:48,060
such as these guys so on and so you would become a very very long string and it would be very tedious

149
00:10:48,060 --> 00:10:49,010
to find them.

150
00:10:49,020 --> 00:10:51,510
So instead I said let's get the numbers on.

151
00:10:51,540 --> 00:10:52,530
Invert them.

152
00:10:52,530 --> 00:10:57,510
Once they have the inverted version I'm going to divide my a string Vider.

153
00:10:57,570 --> 00:11:03,990
So let's call it divide and this thing I want is this one the input string that the text field is providing

154
00:11:03,990 --> 00:11:04,720
for me.

155
00:11:04,740 --> 00:11:06,080
So that's going to be very simple.

156
00:11:06,210 --> 00:11:14,460
I'm going to say Let's call this one or a split or separate and separate it becomes a string of dot

157
00:11:14,520 --> 00:11:22,560
components and separated by remove characters that are separated by doors.

158
00:11:22,560 --> 00:11:29,250
So by now I've got all of these pieces separated and by now I have this data guy and that one on that

159
00:11:29,250 --> 00:11:35,140
one because I'm separating against a character set which is anyone but these.

160
00:11:35,300 --> 00:11:37,740
So it really gets rid of that part.

161
00:11:38,100 --> 00:11:39,220
And at that point.

162
00:11:39,240 --> 00:11:42,280
So then I'm going to go ahead and do what you suggest.

163
00:11:42,330 --> 00:11:44,430
I'm going to join them back to each other.

164
00:11:44,580 --> 00:11:53,000
So let's call this the join and the join is actually going to be let's call it join the string that

165
00:11:53,040 --> 00:11:55,850
becomes anything that we had here.

166
00:11:55,940 --> 00:12:03,370
Separate it separate that just joined and then it says how do you want to join in three.

167
00:12:03,440 --> 00:12:06,850
And I want to join them using a separator.

168
00:12:07,020 --> 00:12:08,760
What is the separator.

169
00:12:08,880 --> 00:12:09,890
Nothing.

170
00:12:10,230 --> 00:12:13,020
I want to join them right to one after another.

171
00:12:13,020 --> 00:12:15,480
I don't want to join them for instance by a space.

172
00:12:15,600 --> 00:12:18,340
If that was the case it would become something like this.

173
00:12:18,430 --> 00:12:22,120
But they want to join them exactly the way they are put them one after another.

174
00:12:22,230 --> 00:12:27,940
So I get that part done and then the next thing I'm going to do and when I say well I have that one.

175
00:12:28,020 --> 00:12:36,930
Now effect here is that if you have a string that was the original one is same as joined which is essentially

176
00:12:36,990 --> 00:12:38,730
this comparison.

177
00:12:38,730 --> 00:12:48,870
Then you have to return true and else you have to return false.

178
00:12:48,870 --> 00:12:52,140
Now let's see quickly what we did once again off the top.

179
00:12:52,140 --> 00:12:58,680
All right I'm going to get rid of all of this and when I say textfield should change tack then inset

180
00:12:59,070 --> 00:13:03,270
is a method that gets called from the textfield delegates.

181
00:13:03,270 --> 00:13:09,770
And it says every time you change something I'm going to call this function I'm going to fire this function

182
00:13:09,810 --> 00:13:16,730
but it's going to be up to the return of it whether I'm actually going to make that change or not.

183
00:13:16,740 --> 00:13:20,190
Now for me I'm going to go ahead and say these are the numbers.

184
00:13:20,220 --> 00:13:24,430
This is the characters that's built from those numbers inverted.

185
00:13:24,450 --> 00:13:32,880
So I get everybody who is not to these guys get my text string that is received in here separated by

186
00:13:32,880 --> 00:13:34,100
these characters.

187
00:13:34,100 --> 00:13:41,040
So if there is a number just keep the numbers separated by those values combine them back with each

188
00:13:41,040 --> 00:13:41,550
other.

189
00:13:41,760 --> 00:13:47,190
And once you combine them back and I think I need to be like that once you combine them back with each

190
00:13:47,190 --> 00:13:49,770
other compare them against each other.

191
00:13:49,830 --> 00:13:54,500
If it was the same as it used to be at the very beginning it means nothing changed.

192
00:13:54,570 --> 00:13:56,610
If it wasn't returned Fox.

193
00:13:56,710 --> 00:14:01,320
Now I was going to change this little bit to a much easier syntax.

194
00:14:01,350 --> 00:14:05,270
I'm going to say this is a true or false statement.

195
00:14:05,340 --> 00:14:12,510
If a string is joined and then if it is true we're going to return true if it is false return false.

196
00:14:12,510 --> 00:14:18,380
So what if we just return this guy that's it's going to say to return a string.

197
00:14:18,420 --> 00:14:19,730
Is it equal to joint.

198
00:14:19,730 --> 00:14:24,060
And if it is true it is going to return true if it is for us is going to return false.

199
00:14:24,120 --> 00:14:26,050
Now let's set this up in practice.

200
00:14:26,100 --> 00:14:34,520
I'm going to load up the app in my simulator and in here we should see if I'm going to boot up the keyboard

201
00:14:34,590 --> 00:14:36,510
when I try the text values.

202
00:14:36,510 --> 00:14:40,070
Nothing shows up then I go to the numeric ones everything works.

203
00:14:40,070 --> 00:14:41,010
Any one else.

204
00:14:41,010 --> 00:14:45,000
Nothing happens only numeric values and numbers can work.

205
00:14:45,150 --> 00:14:56,520
So we could actually combine this by saying my text field dot keyboard type is a keyboard type dot numeric

206
00:14:56,520 --> 00:14:59,950
keypad or a number power or something like that.

207
00:15:00,180 --> 00:15:05,940
And of course on the simulator you can not change the type of the keyboard but on actual device you

208
00:15:05,940 --> 00:15:12,690
could switch back to a different kind of keyboard but here we make sure our user absolutely enters numeric

209
00:15:12,690 --> 00:15:13,680
values.

210
00:15:13,680 --> 00:15:20,190
So that's about that using the delegation and finding the kind of you know functions that you have in

211
00:15:20,190 --> 00:15:23,550
a certain delegate and how you would use them.

212
00:15:23,550 --> 00:15:29,430
Like I said in towards the end of this section a few lessons from now I will show you much easier ways

213
00:15:29,430 --> 00:15:31,700
of finding the delegate methods.

214
00:15:31,710 --> 00:15:33,680
What is available in there.

215
00:15:33,690 --> 00:15:39,450
In all fairness a lot of the things that we don't know is just simply that when you decide to do something

216
00:15:39,450 --> 00:15:45,120
and you you come across an issue then you think to yourself that there might be a delegate method that

217
00:15:45,210 --> 00:15:47,220
does something like that.

218
00:15:47,280 --> 00:15:52,020
For instance there is another delegate method which I kind of forgot its name but they can show it to

219
00:15:52,020 --> 00:15:53,340
you here.

220
00:15:53,340 --> 00:15:55,550
This is the place to delegate.

221
00:15:55,550 --> 00:16:00,570
It means what happens when something gets pasted into my text field.

222
00:16:00,800 --> 00:16:07,070
Do you want to either know pop a little window saying like the one that you have on safari on iPhone

223
00:16:07,140 --> 00:16:12,750
that says the moment you paste something it says Do you want to search for this or do you want to automatically

224
00:16:12,750 --> 00:16:13,820
run the search.

225
00:16:14,020 --> 00:16:21,090
Well a lot of Obstat they allow you to enter text as an authorization when they send you a S-M mess

226
00:16:21,090 --> 00:16:22,230
with a number.

227
00:16:22,350 --> 00:16:23,900
Then you enter the card.

228
00:16:23,910 --> 00:16:25,380
There's one two three four.

229
00:16:25,380 --> 00:16:30,880
The moment you enter the 12:56 it automatically starts checking for authentication.

230
00:16:31,020 --> 00:16:36,870
So based on that you can do a lot of things and a lot of times you wouldn't exactly know what is in

231
00:16:36,870 --> 00:16:37,410
a delegate.

232
00:16:37,410 --> 00:16:43,590
You have to go through the manual and with the help raise resources read about them and find out you

233
00:16:43,590 --> 00:16:49,380
know what you could do with them or more importantly if you have a situation how you could fix it using

234
00:16:49,410 --> 00:16:50,610
any of these.

235
00:16:50,640 --> 00:16:55,770
So let's keep that up to here and then we'll move on to the next lesson which I think will do the same

236
00:16:55,770 --> 00:16:57,240
thing in Objective-C.
