1
00:00:02,970 --> 00:00:05,120
So what can I gain in this exercise.

2
00:00:05,130 --> 00:00:11,390
You're going to develop an app that lets users play a very simple game and that is how fast they can

3
00:00:11,390 --> 00:00:12,130
tap.

4
00:00:12,140 --> 00:00:17,360
So you would have a timeout let's say for five seconds or 10 seconds or 20 seconds and the user has

5
00:00:17,360 --> 00:00:19,340
to top as fast as they can.

6
00:00:19,440 --> 00:00:23,590
And your app is essentially going to chance the number of the taps that they land.

7
00:00:23,660 --> 00:00:26,660
So tap really fast and count the time.

8
00:00:26,660 --> 00:00:27,690
That's the goal.

9
00:00:27,740 --> 00:00:31,090
Let's pause the video now and try it on your own.

10
00:00:31,100 --> 00:00:36,170
And once you're done or if you felt like you know you want to tag along with my solution or look at

11
00:00:36,170 --> 00:00:39,520
what I'm doing I'm going to pause now for a few seconds and then get the song

12
00:00:42,570 --> 00:00:42,960
OK.

13
00:00:43,030 --> 00:00:50,050
So when I go to school and when I start a new application called the top fast as you can imagine some

14
00:00:50,050 --> 00:00:54,790
parts of this I'm actually not going to explain because I'm thinking that you know what's happening

15
00:00:55,750 --> 00:00:58,690
because it's been a while that we are here.

16
00:00:58,780 --> 00:01:02,650
So I'm going to go ahead and add a you I view is I view.

17
00:01:02,660 --> 00:01:05,110
I'm going to kind of place it there.

18
00:01:07,040 --> 00:01:07,550
OK.

19
00:01:07,620 --> 00:01:09,350
So that's kind of there.

20
00:01:09,570 --> 00:01:15,090
I'm actually going to go ahead and make this a little bit of a different color then I'm going to go

21
00:01:15,090 --> 00:01:17,260
ahead and add a label.

22
00:01:18,920 --> 00:01:23,870
And when I'm doing this kind of exercises for you but I don't bother with the utterly out of things

23
00:01:23,870 --> 00:01:27,340
of the source because I kind of feel like you know how to do them.

24
00:01:27,350 --> 00:01:31,500
And also they're not really the goal of this lesson in particular.

25
00:01:31,520 --> 00:01:33,930
You know how to set your values.

26
00:01:34,170 --> 00:01:40,510
And here is that number counter that's the one that counts how many of them are there and this one is

27
00:01:40,510 --> 00:01:42,660
going to be my time counter.

28
00:01:42,840 --> 00:01:47,490
So something like that would do.

29
00:01:47,560 --> 00:01:48,630
Perfect.

30
00:01:48,880 --> 00:01:49,240
OK.

31
00:01:49,240 --> 00:01:53,110
So then I'm going to go in and say these three.

32
00:01:53,110 --> 00:01:54,610
They have outlets.

33
00:01:54,700 --> 00:01:58,110
This one I'm going to call the tap area.

34
00:01:58,660 --> 00:02:03,720
That's where we can top this one is going to be time table.

35
00:02:03,940 --> 00:02:13,230
This is how much time has elapsed so far and this is the number of the counts so counts labor or.

36
00:02:13,570 --> 00:02:16,420
Yeah let's call it top sleep.

37
00:02:16,630 --> 00:02:20,490
I think tops count but I would make more sense.

38
00:02:21,340 --> 00:02:21,830
OK.

39
00:02:21,890 --> 00:02:23,920
So we have all the elements that we need.

40
00:02:23,960 --> 00:02:27,520
And I know that they use an instruction is enabled.

41
00:02:27,590 --> 00:02:31,790
I'm actually going to disable it here so I can show you how to do it in the code even though it doesn't

42
00:02:31,790 --> 00:02:32,730
really matter.

43
00:02:32,740 --> 00:02:41,140
But so we can have a look at that and what a lot of you control and in here we have to do a few things.

44
00:02:41,150 --> 00:02:45,850
I'm going to write all of them down in honor of you Lord.

45
00:02:46,100 --> 00:02:52,250
We have to say what do they call the tap area not use any instruction enabled.

46
00:02:52,250 --> 00:02:53,040
Is that true.

47
00:02:53,120 --> 00:02:55,800
So that's the very very first thing we have to do.

48
00:02:55,910 --> 00:03:00,920
Then we have to have a timer to call in the time that has passed.

49
00:03:00,920 --> 00:03:07,690
We have to have a timer that counts that time and we have to have they count home any time we have stopped.

50
00:03:07,700 --> 00:03:09,770
So let's go ahead and add all three of these.

51
00:03:09,980 --> 00:03:15,570
I'm going to say we have a conference time which is obviously in danger.

52
00:03:15,670 --> 00:03:24,590
Currently we don't have value for it and then we have a timer and this is going to be a timer and that

53
00:03:24,590 --> 00:03:30,430
I have a count which is again an integer and doesn't have a value at the beginning.

54
00:03:30,560 --> 00:03:36,350
So current time counts the time Count counts how many times you tapped on the timer.

55
00:03:36,380 --> 00:03:40,430
Essentially time's up as the time goes through.

56
00:03:40,430 --> 00:03:44,960
Now here's what I'm going to do in my view with a lot of the very first thing I'm going to say every

57
00:03:44,960 --> 00:03:49,270
time we come in here make sure that the count is zero.

58
00:03:50,860 --> 00:03:55,320
Time or were they called the Koren's time is also zero.

59
00:03:55,750 --> 00:04:05,560
And then they start a Timelash and we do that by saying timer becomes a timer that is scheduled timer

60
00:04:05,630 --> 00:04:07,110
we enter.

61
00:04:07,440 --> 00:04:19,180
And the one that I want to use is scheduling timer 1 and let me get all of them in order so I know what

62
00:04:19,180 --> 00:04:23,230
they have to type some time into when I'm going to say it every cycle.

63
00:04:23,290 --> 00:04:26,250
Target is going to be in here.

64
00:04:26,490 --> 00:04:27,950
Let's select what I have to make sure.

65
00:04:27,960 --> 00:04:28,860
Right.

66
00:04:29,050 --> 00:04:37,500
We don't have that and then write this later use it for is national and repeats through and now the

67
00:04:37,500 --> 00:04:40,790
important thing in here is where does this time go.

68
00:04:40,830 --> 00:04:43,400
Every one I can go to every So.

69
00:04:43,470 --> 00:04:49,060
So that's going to be a method that I'm going to call it let's say count it or count time.

70
00:04:49,110 --> 00:04:51,730
It's going to be a function Count.

71
00:04:51,780 --> 00:04:58,360
Count time and my chance time is the one I'm going to use in here.

72
00:04:58,560 --> 00:05:02,330
You know the moment they paste this I'm going to get a warning error.

73
00:05:02,400 --> 00:05:10,430
They're saying that it has to be exposed as an objective c so object C and this is swift for mother

74
00:05:10,740 --> 00:05:17,400
the previous fiefs they used to deal with it differently in the previous issue with I should say something

75
00:05:17,400 --> 00:05:18,110
like this.

76
00:05:18,110 --> 00:05:23,820
You could say in the name of your your function but that really doesn't work anymore.

77
00:05:24,150 --> 00:05:34,020
So let's go back in my chance time I'm going to go ahead and say the one that is called Our Time label

78
00:05:34,530 --> 00:05:43,290
time label that text and becomes essentially any value that you find in the current time.

79
00:05:43,290 --> 00:05:48,570
Now this is obviously going to be very crude if you want to make it look pretty you could actually do

80
00:05:48,690 --> 00:05:50,260
your own formatting.

81
00:05:50,370 --> 00:05:51,120
You can afford it.

82
00:05:51,140 --> 00:05:57,960
It looks like it does 00 the minute sign on a column and then number three I can sign it.

83
00:05:58,020 --> 00:05:59,200
I'm not going to bother with that.

84
00:05:59,280 --> 00:06:01,450
I'm going to show it to you sometime in the future.

85
00:06:01,470 --> 00:06:07,730
But for now this would very much do the work for me it only shows me the exact second that you are on.

86
00:06:07,730 --> 00:06:12,630
And the warning that we have is because crying's time is a function an optional value.

87
00:06:12,780 --> 00:06:15,540
So I'm just going to go ahead and drop it.

88
00:06:15,570 --> 00:06:21,470
And then of course every time we come in here we have to say Cronin's time plus a call 1.

89
00:06:21,540 --> 00:06:25,280
So they have to add that all the time every time that we come in here.

90
00:06:25,470 --> 00:06:27,070
Now here's the thing.

91
00:06:27,400 --> 00:06:33,960
We shouldn't keep doing this forever because we said are essential is going to work for five seconds

92
00:06:33,960 --> 00:06:36,750
or 10 or 30 or any number that you decide.

93
00:06:36,750 --> 00:06:46,290
So for that I'm going to say if time is still below 10 for instance do all of these right and that's

94
00:06:46,290 --> 00:06:48,980
perfectly fine otherwise.

95
00:06:49,260 --> 00:06:57,150
I want to say Taimur daughter in law dictates and then do your own thing to move to a different view

96
00:06:57,150 --> 00:07:02,580
control her show a little warning sign or whatever that you want to do and your user knows that time

97
00:07:02,580 --> 00:07:03,290
is up.

98
00:07:03,420 --> 00:07:05,530
But for now here's what we want to do.

99
00:07:05,540 --> 00:07:14,000
Maybe you want to have a boolean value that is a game of status let's say status.

100
00:07:14,140 --> 00:07:16,750
The beginning it is true.

101
00:07:17,520 --> 00:07:26,400
And then here if that time passes and reaches that status becomes a false value or anything of the sort

102
00:07:26,400 --> 00:07:31,830
that you want to imagine but you have to find a way to announce to you or use it that the time has actually

103
00:07:32,400 --> 00:07:36,680
passed you have reached the time that you can play the game anymore.

104
00:07:37,020 --> 00:07:38,700
So let's keep it here.

105
00:07:38,970 --> 00:07:46,650
Then we move on to adding our actual function which is when we land a touch or when a touch ends which

106
00:07:46,680 --> 00:07:49,880
we should calculate the new count.

107
00:07:49,950 --> 00:07:58,290
So I'm going to go in here and say I have a Hatcher's in that method and in my pictures and I want to

108
00:07:58,290 --> 00:07:59,750
do something very simple.

109
00:07:59,790 --> 00:08:05,820
I want to say if touch does not count is 1.

110
00:08:05,850 --> 00:08:11,350
So I only count it when there is absolutely only one touch on that device.

111
00:08:11,370 --> 00:08:19,290
I'm going to say in that case let's get my touch just like the last times touchiest first and then say

112
00:08:19,490 --> 00:08:29,730
if my touch data view is what we call it tap area if it is a top area then that is when you have to

113
00:08:29,730 --> 00:08:35,520
count up by saying count plus equal 1.

114
00:08:35,540 --> 00:08:44,520
And of course you want to see the value of it tap's count labor and then tax count the text becomes

115
00:08:44,970 --> 00:08:49,650
whatever value we have in the actual counts.

116
00:08:49,920 --> 00:08:55,130
So count I was off to make my count to become mine on dropped value.

117
00:08:55,140 --> 00:08:58,360
So we do that because Count is an optional one.

118
00:08:58,770 --> 00:09:03,100
And now everything should be working the way we wanted it to be working.

119
00:09:03,450 --> 00:09:06,280
Let me go ahead and run this application.

120
00:09:06,480 --> 00:09:09,980
And now the timing is starting to count to three.

121
00:09:10,020 --> 00:09:17,430
And then I can and I can count obviously I'm guessing I do this faster on the mouse and you probably

122
00:09:17,430 --> 00:09:19,620
wouldn't be able to do it as fast.

123
00:09:19,620 --> 00:09:26,700
And once we got to nine it stopped counting maybe this value should have been a smaller or equal 10

124
00:09:26,970 --> 00:09:33,060
and you might want to have a system to format this text better but the overall thing is you'll start

125
00:09:33,060 --> 00:09:39,530
at tight timer between a certain time and until the time reaches a certain value.

126
00:09:39,710 --> 00:09:46,640
And within those two APBA the same Surely you start counting and for now I can still count up even though

127
00:09:46,640 --> 00:09:48,290
the timer has stopped.

128
00:09:48,320 --> 00:09:53,630
That's why I suggested that you probably want to add something like Stathis in here that doesn't let

129
00:09:53,630 --> 00:09:54,890
me do that.

130
00:09:54,890 --> 00:09:57,080
Let me go ahead and quickly add that one.

131
00:09:57,080 --> 00:09:59,400
I'm going to say.

132
00:09:59,930 --> 00:10:02,090
Let's say play.

133
00:10:02,200 --> 00:10:02,610
OK.

134
00:10:02,720 --> 00:10:05,920
And that's going to be currently true.

135
00:10:06,380 --> 00:10:10,560
And I'm going to say play vidit become false.

136
00:10:10,940 --> 00:10:17,360
If the timer reaches there's so so far we know at the moment we reach 10 seconds.

137
00:10:17,370 --> 00:10:19,260
Play will become fots.

138
00:10:19,280 --> 00:10:20,720
So how does that help pause.

139
00:10:20,750 --> 00:10:27,530
I'm going to go to touches in it and say touches touch that one and play.

140
00:10:27,660 --> 00:10:30,820
So only do this thing you feel are in the play mode.

141
00:10:30,860 --> 00:10:33,650
If you another the play more don't do any of these things.

142
00:10:33,920 --> 00:10:35,960
So let's run up again.

143
00:10:36,230 --> 00:10:39,290
And these are really simple fix this so much you can do.

144
00:10:39,290 --> 00:10:41,990
That's why I don't want to go through every single detail.

145
00:10:42,020 --> 00:10:44,300
You can do a lot of these things on your own.

146
00:10:44,300 --> 00:10:46,260
So now my time is counting up.

147
00:10:46,260 --> 00:10:47,010
I have four.

148
00:10:47,030 --> 00:10:49,790
I can tap tap tap tap tap tap tap tap tap.

149
00:10:49,900 --> 00:10:55,420
Twenty four five six seven and then you starts at 10.

150
00:10:55,420 --> 00:10:57,060
I couldn't tap anymore.

151
00:10:57,160 --> 00:11:02,390
It got stuck at 41 and that's simply because now play is false.

152
00:11:02,800 --> 00:11:06,070
So that's about that there's so much you can still fix on this.

153
00:11:06,060 --> 00:11:11,620
Our playing style is one of the things that happens and that's a logical error is that I wanted this

154
00:11:11,620 --> 00:11:13,810
to happen only for the first 10 seconds.

155
00:11:13,830 --> 00:11:21,500
But I know I'm actually working up until the 11th and because this runs at the tenth time and it becomes

156
00:11:21,580 --> 00:11:27,070
valid and then one more second passes before this thing becomes false.

157
00:11:27,070 --> 00:11:29,310
So that's something you might want to address.

158
00:11:29,320 --> 00:11:34,760
The other thing is right at the beginning of the app we don't see the timer showing us zero.

159
00:11:34,890 --> 00:11:38,400
You might win at least not until this becomes a real application.

160
00:11:38,410 --> 00:11:41,490
Obviously you need to write a lot more code.

161
00:11:41,980 --> 00:11:44,390
Like what 60 lines of code.

162
00:11:44,440 --> 00:11:50,440
You'll probably need to reach it to about 100 150 before everything is taking care off and everything

163
00:11:50,440 --> 00:11:51,290
is at risk.

164
00:11:51,470 --> 00:11:56,310
Another thing is probably you want to allow you to use it to start the game on their own.

165
00:11:56,350 --> 00:12:01,090
It's never a good idea to start the game on a view that lot simply because there might be a little bit

166
00:12:01,090 --> 00:12:03,440
of a delay until the view did last.

167
00:12:03,460 --> 00:12:05,290
And the view did appear to happen.

168
00:12:05,320 --> 00:12:07,930
So maybe you want to have a little button that says begin.

169
00:12:07,960 --> 00:12:10,940
And then when they first to begin they kind of start tapping.

170
00:12:11,050 --> 00:12:14,700
So on and so forth there's so much that you know you can do about it.

171
00:12:14,710 --> 00:12:17,020
So with that in mind let's move on to on.
