1
00:00:05,370 --> 00:00:06,730
Hey what's up guys.

2
00:00:06,740 --> 00:00:11,030
I'm Jacob blitzed with Def slips dot com in this lesson.

3
00:00:11,090 --> 00:00:16,110
We're going to get our duration timer working and formatted.

4
00:00:16,610 --> 00:00:18,130
So that's going to be really cool.

5
00:00:18,140 --> 00:00:23,820
Last time we got our distance finally working and we have it all formatted for meters to Miles.

6
00:00:23,990 --> 00:00:29,690
And obviously if you want kilometers you can just change that extension that we made and you have your

7
00:00:29,690 --> 00:00:31,410
kilometers.

8
00:00:31,460 --> 00:00:35,570
So in this lesson we need to start a duration timer right.

9
00:00:35,600 --> 00:00:43,390
And so that'll be in our Start Run we'll probably have like us start timer function.

10
00:00:43,400 --> 00:00:52,040
So inside of our Start Run why don't we just call start timer cool and underneath and run let's go ahead

11
00:00:52,040 --> 00:01:01,730
and make a function func start timer and opening and closing brackets and all right.

12
00:01:01,730 --> 00:01:05,460
So let's also we need a variable for our timer right.

13
00:01:05,510 --> 00:01:12,770
So underneath run distance Let's go ahead and just do var counter or you call it timer or whatever you

14
00:01:12,770 --> 00:01:15,030
want and set it to zero.

15
00:01:15,290 --> 00:01:20,630
So this is just going to be an integer and it's just going to keep track of seconds for us and then

16
00:01:20,630 --> 00:01:30,100
we are going to put an extension on type integer and do our whole formatting thing that we did before

17
00:01:30,460 --> 00:01:32,200
with meters to Miles.

18
00:01:32,200 --> 00:01:41,820
But we're going to format the timer from seconds to our minutes and seconds format.

19
00:01:41,840 --> 00:01:49,530
And so it'll be really cool just like our label if you remember I don't let's say let's just pull up

20
00:01:49,530 --> 00:01:51,420
our docs real quick.

21
00:01:52,830 --> 00:01:55,300
On run here we go.

22
00:01:55,610 --> 00:02:04,550
So basically we'll have you know are our hours minutes and seconds and that is we're going to format

23
00:02:04,640 --> 00:02:06,120
seconds to display it.

24
00:02:06,140 --> 00:02:08,600
All three of those.

25
00:02:08,610 --> 00:02:14,610
All right so we have our counter which is just an integer which is great.

26
00:02:14,720 --> 00:02:19,770
And then we need to create a our start timer function.

27
00:02:19,820 --> 00:02:30,660
So the first thing would be we need to format or we would need to start a timer right.

28
00:02:31,910 --> 00:02:40,020
So to create a timer we're going to need a another variable and we'll put it underneath a last location

29
00:02:40,020 --> 00:02:49,910
so var timer and timer is going to be equal to a instance of timer just like that.

30
00:02:49,930 --> 00:02:57,120
So we have our timer here and now in start timer we just have to set it up so to set up our timer.

31
00:02:57,160 --> 00:03:01,080
Let's go ahead and start timer function.

32
00:03:01,210 --> 00:03:08,550
Let's go ahead and do timer equals timer capital for timer scheduled timer.

33
00:03:08,830 --> 00:03:11,330
And we want it with interval.

34
00:03:11,740 --> 00:03:20,980
We want it not we don't want the repeating one we want to have the selector.

35
00:03:20,990 --> 00:03:23,730
Here we go this is what we want.

36
00:03:24,960 --> 00:03:34,770
OK so our interval is going to be one we want to count one value every time it gets called The Target

37
00:03:34,830 --> 00:03:44,320
self and our selector is going to be a function that we have to make right after this.

38
00:03:44,820 --> 00:03:48,870
But we'll call our function like Update counter.

39
00:03:49,770 --> 00:03:50,480
OK.

40
00:03:50,520 --> 00:03:56,890
And then the user info we don't need nyl and we want this to repeat Trews.

41
00:03:56,890 --> 00:04:01,980
So this is constantly going to be running when we're in this Visi and it's yelling at us because it

42
00:04:01,980 --> 00:04:02,530
doesn't know where.

43
00:04:02,570 --> 00:04:04,880
Update timer so underneath start timer.

44
00:04:05,100 --> 00:04:09,000
Let's make another function and call this update counter.

45
00:04:11,580 --> 00:04:19,600
Our cool and inside update counter are variable we created at the top.

46
00:04:19,600 --> 00:04:24,260
Instead it's a zero let's just say counter plus equals 1.

47
00:04:24,260 --> 00:04:28,680
So we're just going to add 1 to it every time this is called.

48
00:04:28,740 --> 00:04:30,610
Which is it makes sense right.

49
00:04:30,660 --> 00:04:35,910
And then we also want to take our duration label dot text.

50
00:04:36,060 --> 00:04:42,630
Whoops I can't get the period text and we want that to equal our counter.

51
00:04:42,630 --> 00:04:43,490
Right.

52
00:04:43,510 --> 00:04:44,930
All right cool.

53
00:04:45,670 --> 00:04:48,630
And we should probably have our start timer.

54
00:04:49,780 --> 00:04:55,440
Also set our duration level as well.

55
00:04:55,440 --> 00:05:01,500
So duration dot text equals counter that way.

56
00:05:01,500 --> 00:05:06,390
Start timers only called once but we want our label to be updated to zero right away right.

57
00:05:06,390 --> 00:05:12,040
Without using the default storyboard label.

58
00:05:12,070 --> 00:05:19,750
So with this being done we're going to now display segments on our Visi what doesn't.

59
00:05:19,790 --> 00:05:21,100
Oh I have to just

60
00:05:29,770 --> 00:05:31,330
you go.

61
00:05:34,680 --> 00:05:38,140
At once a string because it's a label.

62
00:05:38,280 --> 00:05:40,780
So we'll just print this for now.

63
00:05:41,130 --> 00:05:46,110
But the problem is it's just going to show one integer it's going to be seconds.

64
00:05:46,110 --> 00:05:46,490
Right.

65
00:05:46,500 --> 00:05:51,240
And that's not how we want to display but we'll make sure our timer works.

66
00:05:51,240 --> 00:05:53,090
So go ahead and press start.

67
00:05:53,100 --> 00:05:54,490
Run.

68
00:05:54,650 --> 00:05:59,260
And there we go our timer is counting up our distances move in.

69
00:05:59,360 --> 00:06:03,080
And if your distance isn't moving de-bug location city run.

70
00:06:03,080 --> 00:06:06,080
So our timer works but now we just need to format it.

71
00:06:06,080 --> 00:06:15,380
So it looks nice because if it gets over 60 seconds it's going to be pretty unreadable at a glance right.

72
00:06:15,410 --> 00:06:26,410
So let's go ahead and create our extension off of integer or we should extend and.

73
00:06:26,520 --> 00:06:28,450
So let's open our extensions.

74
00:06:28,710 --> 00:06:31,970
Class or file.

75
00:06:32,160 --> 00:06:41,310
And we want to now extent an extension off of int it opening and closing brackets and we will call this

76
00:06:41,790 --> 00:06:46,920
function format time duration

77
00:06:49,310 --> 00:06:50,590
2 string.

78
00:06:50,600 --> 00:06:58,140
So we're we're actually going to change our integer directly into a string before we return it.

79
00:06:58,140 --> 00:07:04,240
So we don't have to cast it in the label later it'll just make our lives a little easier.

80
00:07:04,460 --> 00:07:10,440
So let's go ahead and call this format time duration to string and we're returning a string.

81
00:07:10,970 --> 00:07:17,030
So this is also cool because you extending and right and you're not returning and you're actually returning

82
00:07:17,030 --> 00:07:19,670
a string so that's cool.

83
00:07:19,850 --> 00:07:21,890
And let's see we're passing.

84
00:07:21,900 --> 00:07:29,810
And so we're going to be formatting and integer and we need duration for hours minutes and seconds.

85
00:07:32,640 --> 00:07:43,410
So let's set up a variable for lat duration of hours equal self and we need to divide the integer to

86
00:07:43,410 --> 00:07:46,340
figure out hours by 3600.

87
00:07:46,770 --> 00:07:50,320
And that's because there are thirty six hundred seconds in an hour.

88
00:07:50,760 --> 00:07:59,720
And now we need to also create a variable for duration minutes and that is going to be equal to.

89
00:07:59,830 --> 00:08:02,430
We need a opening in parentheses.

90
00:08:02,430 --> 00:08:03,470
So we need self.

91
00:08:03,510 --> 00:08:08,030
And then we're going to use a modulus 3600.

92
00:08:08,220 --> 00:08:18,600
And what that does it's going to return how many times we can divide thirty six hundred into it.

93
00:08:20,810 --> 00:08:27,620
And then once we know that we can then divide by 60 which there are 60 Minutes in an hour and that will

94
00:08:27,620 --> 00:08:35,850
give us how many minutes are in the integer of seconds we just passed in and then we all are going to

95
00:08:35,850 --> 00:08:42,030
do the same thing for seconds so that duration seconds equal

96
00:08:44,910 --> 00:08:55,270
self modulus 3600 and then we also want to have this one return.

97
00:08:55,270 --> 00:08:56,200
How many times

98
00:09:00,740 --> 00:09:10,040
seconds can be divisible into the remaining value so we're going to do another modulus 60.

99
00:09:10,670 --> 00:09:18,410
And that is going to give us how many seconds are left in this integer we passed in and then we can

100
00:09:18,410 --> 00:09:25,810
do some cool things like if duration.

101
00:09:26,010 --> 00:09:30,540
Second chance is less than zero.

102
00:09:30,540 --> 00:09:33,760
That means it would actually return zero.

103
00:09:33,790 --> 00:09:40,230
Right well you still want it to return a value that we want to see so we can just return the string

104
00:09:40,260 --> 00:09:45,030
of 0 0 0 0 0 0.

105
00:09:45,030 --> 00:09:46,920
So that's what we want it to look like.

106
00:09:46,980 --> 00:10:01,660
If there is no value and then else we can also do like if duration hours isn't equal to zero or is equal

107
00:10:01,660 --> 00:10:02,850
to zero I'm sorry.

108
00:10:03,070 --> 00:10:08,030
Then we will return a string.

109
00:10:08,110 --> 00:10:08,650
Whoops.

110
00:10:08,680 --> 00:10:10,120
I'm having struggles here.

111
00:10:10,690 --> 00:10:23,170
A string of type format and the way you format a string now is you create a string and you do a percent

112
00:10:23,170 --> 00:10:23,690
sign.

113
00:10:23,710 --> 00:10:25,700
And then we want two places.

114
00:10:25,720 --> 00:10:30,980
So we always want if only like a single integers return like one or two.

115
00:10:31,120 --> 00:10:36,970
We want to make sure the second below far left field still has a value in it.

116
00:10:37,090 --> 00:10:44,330
And so we are going to put a 0 0 here and that means it'll always be filled with a 2.

117
00:10:44,440 --> 00:10:46,460
Or I mean I'm sorry.

118
00:10:47,020 --> 00:10:50,920
We always want two spots in this field right.

119
00:10:51,100 --> 00:10:54,230
And if there is only one it will put a zero there.

120
00:10:54,340 --> 00:10:55,610
That's what that means.

121
00:10:55,780 --> 00:10:57,510
And then we'll put our colon.

122
00:10:57,730 --> 00:11:00,940
And we want the same thing as 0 2.

123
00:11:01,150 --> 00:11:06,070
And we also need Deese there because they are type double.

124
00:11:06,360 --> 00:11:13,400
And then we just end our quotation and then arguments we pass in here since duration ours is zero.

125
00:11:13,410 --> 00:11:18,530
We just pass and duration minutes and duration seconds.

126
00:11:19,230 --> 00:11:26,220
And so this will get passed here and then duration seconds will get passed here and then so if duration

127
00:11:26,250 --> 00:11:28,540
hours isn't equal to zero.

128
00:11:28,800 --> 00:11:38,500
We want to return all three locations with the values so format opening and closing parentheses percent.

129
00:11:38,520 --> 00:11:43,120
0 2 d Colan percent 0 2 D.

130
00:11:43,160 --> 00:11:47,600
Colon and percent zero D.

131
00:11:49,040 --> 00:11:58,950
And then our arguments would be duration hours duration minutes and duration seconds.

132
00:12:00,380 --> 00:12:04,870
And that will return our formatted label for us.

133
00:12:04,880 --> 00:12:13,190
So now let's go ahead and go back to our current current run Visi and where the counter is let's just

134
00:12:13,190 --> 00:12:22,670
delete our our string where we can add the variable in and just call counter and we can say Dot.

135
00:12:22,730 --> 00:12:31,250
And we want to format time duration to string and then same in our update counter counter data format

136
00:12:31,250 --> 00:12:33,170
time duration 2 string.

137
00:12:33,380 --> 00:12:35,250
And let's go ahead and run this.

138
00:12:35,270 --> 00:12:41,400
And we should now see our cool label being updated and formatted properly.

139
00:12:45,690 --> 00:12:52,210
All right so now if we just press Start Run There we go with that.

140
00:12:52,220 --> 00:12:59,090
Our seconds are there and minutes will fill in there and our hours are missing until the run would get

141
00:12:59,090 --> 00:13:01,100
that long of an hours would appear.

142
00:13:01,100 --> 00:13:02,450
So that's really cool.

143
00:13:03,970 --> 00:13:05,350
So we are getting there guys.

144
00:13:05,350 --> 00:13:10,660
I'm going to call this video done before we are there let's go ahead and pull up our terminal and make

145
00:13:10,660 --> 00:13:23,050
sure we commit this so get ad period get commit Desch am and we got our duration timer functioning.

146
00:13:23,710 --> 00:13:30,900
All right sweet guys in the next run or in the next lesson we are going to get our average pace working.

147
00:13:31,060 --> 00:13:37,630
So if you guys want to stretch your abilities you should try to get that working before starting the

148
00:13:37,630 --> 00:13:38,640
next lesson.

149
00:13:38,890 --> 00:13:40,590
And then if you get stuck.

150
00:13:40,630 --> 00:13:44,250
Watch the next lesson and I will help you figure it out.

151
00:13:44,260 --> 00:13:44,530
All right.

152
00:13:44,530 --> 00:13:45,730
So I will see you in the next lesson.
