So what can I gain in this exercise.
You're going to develop an app that lets users play a very simple game and that is how fast they can
tap.
So you would have a timeout let's say for five seconds or 10 seconds or 20 seconds and the user has
to top as fast as they can.
And your app is essentially going to chance the number of the taps that they land.
So tap really fast and count the time.
That's the goal.
Let's pause the video now and try it on your own.
And once you're done or if you felt like you know you want to tag along with my solution or look at
what I'm doing I'm going to pause now for a few seconds and then get the song
OK.
So when I go to school and when I start a new application called the top fast as you can imagine some
parts of this I'm actually not going to explain because I'm thinking that you know what's happening
because it's been a while that we are here.
So I'm going to go ahead and add a you I view is I view.
I'm going to kind of place it there.
OK.
So that's kind of there.
I'm actually going to go ahead and make this a little bit of a different color then I'm going to go
ahead and add a label.
And when I'm doing this kind of exercises for you but I don't bother with the utterly out of things
of the source because I kind of feel like you know how to do them.
And also they're not really the goal of this lesson in particular.
You know how to set your values.
And here is that number counter that's the one that counts how many of them are there and this one is
going to be my time counter.
So something like that would do.
Perfect.
OK.
So then I'm going to go in and say these three.
They have outlets.
This one I'm going to call the tap area.
That's where we can top this one is going to be time table.
This is how much time has elapsed so far and this is the number of the counts so counts labor or.
Yeah let's call it top sleep.
I think tops count but I would make more sense.
OK.
So we have all the elements that we need.
And I know that they use an instruction is enabled.
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
really matter.
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.
I'm going to write all of them down in honor of you Lord.
We have to say what do they call the tap area not use any instruction enabled.
Is that true.
So that's the very very first thing we have to do.
Then we have to have a timer to call in the time that has passed.
We have to have a timer that counts that time and we have to have they count home any time we have stopped.
So let's go ahead and add all three of these.
I'm going to say we have a conference time which is obviously in danger.
Currently we don't have value for it and then we have a timer and this is going to be a timer and that
I have a count which is again an integer and doesn't have a value at the beginning.
So current time counts the time Count counts how many times you tapped on the timer.
Essentially time's up as the time goes through.
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
time we come in here make sure that the count is zero.
Time or were they called the Koren's time is also zero.
And then they start a Timelash and we do that by saying timer becomes a timer that is scheduled timer
we enter.
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
they have to type some time into when I'm going to say it every cycle.
Target is going to be in here.
Let's select what I have to make sure.
Right.
We don't have that and then write this later use it for is national and repeats through and now the
important thing in here is where does this time go.
Every one I can go to every So.
So that's going to be a method that I'm going to call it let's say count it or count time.
It's going to be a function Count.
Count time and my chance time is the one I'm going to use in here.
You know the moment they paste this I'm going to get a warning error.
They're saying that it has to be exposed as an objective c so object C and this is swift for mother
the previous fiefs they used to deal with it differently in the previous issue with I should say something
like this.
You could say in the name of your your function but that really doesn't work anymore.
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
time label that text and becomes essentially any value that you find in the current time.
Now this is obviously going to be very crude if you want to make it look pretty you could actually do
your own formatting.
You can afford it.
It looks like it does 00 the minute sign on a column and then number three I can sign it.
I'm not going to bother with that.
I'm going to show it to you sometime in the future.
But for now this would very much do the work for me it only shows me the exact second that you are on.
And the warning that we have is because crying's time is a function an optional value.
So I'm just going to go ahead and drop it.
And then of course every time we come in here we have to say Cronin's time plus a call 1.
So they have to add that all the time every time that we come in here.
Now here's the thing.
We shouldn't keep doing this forever because we said are essential is going to work for five seconds
or 10 or 30 or any number that you decide.
So for that I'm going to say if time is still below 10 for instance do all of these right and that's
perfectly fine otherwise.
I want to say Taimur daughter in law dictates and then do your own thing to move to a different view
control her show a little warning sign or whatever that you want to do and your user knows that time
is up.
But for now here's what we want to do.
Maybe you want to have a boolean value that is a game of status let's say status.
The beginning it is true.
And then here if that time passes and reaches that status becomes a false value or anything of the sort
that you want to imagine but you have to find a way to announce to you or use it that the time has actually
passed you have reached the time that you can play the game anymore.
So let's keep it here.
Then we move on to adding our actual function which is when we land a touch or when a touch ends which
we should calculate the new count.
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
do something very simple.
I want to say if touch does not count is 1.
So I only count it when there is absolutely only one touch on that device.
I'm going to say in that case let's get my touch just like the last times touchiest first and then say
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
count up by saying count plus equal 1.
And of course you want to see the value of it tap's count labor and then tax count the text becomes
whatever value we have in the actual counts.
So count I was off to make my count to become mine on dropped value.
So we do that because Count is an optional one.
And now everything should be working the way we wanted it to be working.
Let me go ahead and run this application.
And now the timing is starting to count to three.
And then I can and I can count obviously I'm guessing I do this faster on the mouse and you probably
wouldn't be able to do it as fast.
And once we got to nine it stopped counting maybe this value should have been a smaller or equal 10
and you might want to have a system to format this text better but the overall thing is you'll start
at tight timer between a certain time and until the time reaches a certain value.
And within those two APBA the same Surely you start counting and for now I can still count up even though
the timer has stopped.
That's why I suggested that you probably want to add something like Stathis in here that doesn't let
me do that.
Let me go ahead and quickly add that one.
I'm going to say.
Let's say play.
OK.
And that's going to be currently true.
And I'm going to say play vidit become false.
If the timer reaches there's so so far we know at the moment we reach 10 seconds.
Play will become fots.
So how does that help pause.
I'm going to go to touches in it and say touches touch that one and play.
So only do this thing you feel are in the play mode.
If you another the play more don't do any of these things.
So let's run up again.
And these are really simple fix this so much you can do.
That's why I don't want to go through every single detail.
You can do a lot of these things on your own.
So now my time is counting up.
I have four.
I can tap tap tap tap tap tap tap tap tap.
Twenty four five six seven and then you starts at 10.
I couldn't tap anymore.
It got stuck at 41 and that's simply because now play is false.
So that's about that there's so much you can still fix on this.
Our playing style is one of the things that happens and that's a logical error is that I wanted this
to happen only for the first 10 seconds.
But I know I'm actually working up until the 11th and because this runs at the tenth time and it becomes
valid and then one more second passes before this thing becomes false.
So that's something you might want to address.
The other thing is right at the beginning of the app we don't see the timer showing us zero.
You might win at least not until this becomes a real application.
Obviously you need to write a lot more code.
Like what 60 lines of code.
You'll probably need to reach it to about 100 150 before everything is taking care off and everything
is at risk.
Another thing is probably you want to allow you to use it to start the game on their own.
It's never a good idea to start the game on a view that lot simply because there might be a little bit
of a delay until the view did last.
And the view did appear to happen.
So maybe you want to have a little button that says begin.
And then when they first to begin they kind of start tapping.
So on and so forth there's so much that you know you can do about it.
So with that in mind let's move on to on.