1
00:00:06,550 --> 00:00:10,350
HEY WHAT'S UP GUYS I'M Jacob Blitzer with Debb slopes dot com.

2
00:00:10,350 --> 00:00:15,760
And we got pretty we got our last run showing up on the map view.

3
00:00:15,930 --> 00:00:23,250
And so at the beginning view right here we got this done in the last lesson and we're almost done with

4
00:00:23,250 --> 00:00:23,810
this view.

5
00:00:23,820 --> 00:00:30,750
But we need to do a polyline overlay of our route on the map.

6
00:00:30,840 --> 00:00:35,090
And that would just kind of finish everything off and it would be awesome.

7
00:00:35,130 --> 00:00:41,670
There are a few things we need to discuss though before we go on we need to keep track of all of our

8
00:00:41,670 --> 00:00:43,520
locations right now.

9
00:00:43,830 --> 00:00:47,940
Right now if we go to our current run we have this low.

10
00:00:48,090 --> 00:00:54,870
We were basically adding the distances from our last location to each new location but we're not actually

11
00:00:54,870 --> 00:00:56,570
storing these anywhere.

12
00:00:56,760 --> 00:01:02,670
And for us to draw the polyline on the map we need like a array of locations.

13
00:01:02,730 --> 00:01:07,070
So whenever we pull up that run we can draw the polyline.

14
00:01:07,620 --> 00:01:17,050
So what we're going to have to do is we want to list variable in our run object right and we're going

15
00:01:17,050 --> 00:01:21,270
to have to have it be a list of another object.

16
00:01:21,520 --> 00:01:28,810
So we need to create a location model just to store our two coordinates.

17
00:01:29,050 --> 00:01:39,850
And since that's a C-L location let me see if I can find a location for you in our current run up at

18
00:01:39,850 --> 00:01:41,450
the top.

19
00:01:42,130 --> 00:01:48,580
OK so if we come up here where we declared start and last location there C-L locations and like we were

20
00:01:48,580 --> 00:01:53,640
talking about before that's obviously not a supported type in a role model.

21
00:01:53,770 --> 00:01:56,560
And we have to make a role model for location right.

22
00:01:56,590 --> 00:02:04,360
So let's command click this and right here there's an initialiser where we can pass in a seal location

23
00:02:04,360 --> 00:02:12,160
degrees for latitude and longitude and if we command click on that we find out that it's a double and

24
00:02:12,300 --> 00:02:15,550
hey we can have doubles in role models right.

25
00:02:15,550 --> 00:02:17,490
So that's really cool.

26
00:02:17,740 --> 00:02:26,320
So we need to keep track of an array or in this case it's going to be a list which is a realm list in

27
00:02:26,320 --> 00:02:31,190
our current run we just need to always append our list with the locations right.

28
00:02:31,570 --> 00:02:40,090
So if we go ahead and just create a new data model let's say new file AOS swift file.

29
00:02:40,090 --> 00:02:40,860
Great.

30
00:02:40,990 --> 00:02:52,210
And we're going to call this location save it and we need to import relm swift so to Rome.

31
00:02:52,550 --> 00:02:53,450
Swift.

32
00:02:53,560 --> 00:02:54,350
Right.

33
00:02:54,450 --> 00:03:02,760
And this is going to be a class location and it needs to inherit from the object realm object.

34
00:03:02,760 --> 00:03:03,460
OK.

35
00:03:03,690 --> 00:03:04,930
And now a couple.

36
00:03:04,930 --> 00:03:08,660
So that only we only need two variables in this model right.

37
00:03:08,660 --> 00:03:10,610
We need latitude and longitude.

38
00:03:10,650 --> 00:03:18,780
So let's do our dynamic variable with which if you remember that becomes an ice that allows these variables

39
00:03:18,780 --> 00:03:27,240
to be assessors to the underlying relm database which is super important.

40
00:03:27,240 --> 00:03:34,080
So let's go ahead and do that and we'll do our private set which is our encapsulation and this will

41
00:03:34,080 --> 00:03:40,400
be our latitude and let's set this to zero for now for double zero point zero.

42
00:03:40,710 --> 00:03:49,890
And then we need another variable public private set var and this is longitude and this needs to be

43
00:03:49,890 --> 00:03:51,880
equal to zero point zero.

44
00:03:52,200 --> 00:03:58,200
And then all we have to do is make an initializer for the location object so we'll just do our convenience

45
00:03:59,070 --> 00:04:00,080
in it.

46
00:04:00,480 --> 00:04:11,200
And we just need to pass in latitude which is type double and longitude which is also type double and

47
00:04:11,200 --> 00:04:13,300
I need to capitalize this D.

48
00:04:13,680 --> 00:04:15,440
Get rid of this base.

49
00:04:15,450 --> 00:04:16,240
All right.

50
00:04:16,240 --> 00:04:24,230
And then we just need to do south latitude equals latitude and self-taught longitude equals longitude.

51
00:04:24,230 --> 00:04:25,060
All right.

52
00:04:25,090 --> 00:04:29,500
And that's all we need to do for this model which is really cool.

53
00:04:29,530 --> 00:04:31,530
And why is it yelling at us.

54
00:04:33,210 --> 00:04:34,760
Let's just build our project

55
00:04:37,760 --> 00:04:46,920
oh we need our super in our ourself and called our right and now won't yell at us.

56
00:04:46,940 --> 00:04:53,170
And now in a run model we want to add this location objects to a list.

57
00:04:53,210 --> 00:05:04,030
So the one exception to the rule of using dynamic is optionals and lists I believe.

58
00:05:04,030 --> 00:05:07,760
And let's find that in our

59
00:05:11,600 --> 00:05:21,710
in our documents here it's supported types so if we come down here we can see an example of where.

60
00:05:21,740 --> 00:05:30,000
Let's see they made a dog object right here just kind of like pretend dog is our location and everything

61
00:05:30,030 --> 00:05:34,290
you know he has an owner and they're assigning a person to him that's fine.

62
00:05:34,290 --> 00:05:35,090
Great.

63
00:05:35,130 --> 00:05:39,840
And if we come down here to a person it looks like they can have a list of dogs or an array of different

64
00:05:39,840 --> 00:05:48,240
dogs and list and RELM optionals are the two properties that can't be declared as dynamic because they're

65
00:05:48,240 --> 00:05:53,860
generic properties and they can't be represented in Objective C at runtime.

66
00:05:54,210 --> 00:06:02,830
So this is the one Exeunt the one instance where we can't put dynamic in front of this property.

67
00:06:03,050 --> 00:06:12,260
So when we declare this and run all we're going to do is our public private set in front of it so public

68
00:06:13,070 --> 00:06:14,420
private set.

69
00:06:14,630 --> 00:06:17,570
And this is going to be a Vark of locations.

70
00:06:20,480 --> 00:06:30,430
And it's going to be equal to a type or a list of type location and we'll just make it a empty array

71
00:06:30,520 --> 00:06:31,970
or an empty list right now.

72
00:06:31,980 --> 00:06:32,630
OK.

73
00:06:33,070 --> 00:06:44,110
And so once that is declared we're going to have to change our initialiser to take in a location.

74
00:06:44,400 --> 00:06:48,600
Locations of type of list location

75
00:06:51,140 --> 00:06:52,470
are right.

76
00:06:53,510 --> 00:07:01,880
And then let's go ahead and set our self locations equals locations are right.

77
00:07:01,910 --> 00:07:06,160
And now this model is updated right.

78
00:07:06,170 --> 00:07:12,100
So we have our locations being passed in all we have to add our locations here locations

79
00:07:15,700 --> 00:07:17,560
of locations

80
00:07:21,110 --> 00:07:22,280
and up here.

81
00:07:22,290 --> 00:07:31,200
Forgot it here so locations of type list location.

82
00:07:31,920 --> 00:07:37,820
So that's done now we're going to get an error because our current run isn't passing in enough data.

83
00:07:37,830 --> 00:07:38,560
Right.

84
00:07:38,610 --> 00:07:40,710
So if we go to our current run

85
00:07:44,900 --> 00:07:53,310
our current run we see we're going to have to make a new variable and it's going to be I guess we'll

86
00:07:53,310 --> 00:08:09,340
just call locations so let's say var locations and this is going to be equal to list of location OK

87
00:08:09,370 --> 00:08:16,270
so we're going to now be able to append this whenever we use it.

88
00:08:16,330 --> 00:08:25,380
And now since we're using a realm collection type we have to import realm so import relm Swift.

89
00:08:25,710 --> 00:08:27,400
This air should go way

90
00:08:32,560 --> 00:08:42,310
and since since we're here all these variables and this clash should be file private and in the new

91
00:08:42,490 --> 00:08:44,560
and swift for

92
00:08:47,930 --> 00:08:54,080
private is going to take over and I assume you mean file private so you won't have to do this in the

93
00:08:54,080 --> 00:09:01,760
new Swift but currently file private means that extensions inside your file still have access to these

94
00:09:01,880 --> 00:09:02,800
variables.

95
00:09:02,960 --> 00:09:10,010
If I just made them private our extension down here wouldn't be able to see a start location and location

96
00:09:10,400 --> 00:09:11,750
or last location.

97
00:09:11,870 --> 00:09:13,270
So we'll just make that private.

98
00:09:13,280 --> 00:09:14,060
And then that way.

99
00:09:14,060 --> 00:09:17,350
Other other places can't get.

100
00:09:17,350 --> 00:09:25,880
OK so once we have this location's variable this list we can go ahead and go down to our location manager

101
00:09:25,910 --> 00:09:34,290
where we're updating did locations change down here in our extension of the location manager.

102
00:09:34,310 --> 00:09:43,370
So right under our where we add to our run distance we can actually create a new location object.

103
00:09:43,430 --> 00:09:45,650
So why don't we go ahead and do let.

104
00:09:45,650 --> 00:09:47,500
New location.

105
00:09:49,720 --> 00:09:50,430
Equal.

106
00:09:50,470 --> 00:09:55,390
And then we're just going to call our location model with our initialiser.

107
00:09:55,390 --> 00:10:03,420
There we go and we just pass in the latitude and longitude and we're going to just cast these as a double.

108
00:10:03,490 --> 00:10:13,870
So double and then go ahead and call last location dot coordinate that latitude.

109
00:10:14,340 --> 00:10:14,910
OK.

110
00:10:14,950 --> 00:10:20,650
And then close the parentheses and then for a long G-tube same thing we're going to cast as a double

111
00:10:20,970 --> 00:10:28,310
and we're going to do last location that coordinate dot long as it to our right.

112
00:10:28,480 --> 00:10:36,340
And now we have our new location object created from the last location and now all we have to do is

113
00:10:36,430 --> 00:10:40,280
insert this into the list that we created up above.

114
00:10:40,690 --> 00:10:42,850
And that is called locations.

115
00:10:43,060 --> 00:10:51,340
So let's go ahead and say locations that insert new element perfect and go ahead and put new location

116
00:10:51,340 --> 00:10:55,410
in there and we want to insert this at zero.

117
00:10:56,050 --> 00:11:02,690
So that means all the rest will be shuffled down lists are ordered.

118
00:11:02,710 --> 00:11:07,830
So unlike the results collection lists are ordered like arrays.

119
00:11:07,840 --> 00:11:12,730
So when we insert it at zero it's always going to stay in that same order.

120
00:11:12,730 --> 00:11:15,040
So it's really nice.

121
00:11:15,040 --> 00:11:15,820
All right.

122
00:11:15,820 --> 00:11:26,920
So now that is done and we have to do a self actually let's name our array like coordinate locations

123
00:11:27,810 --> 00:11:32,170
just so it doesn't conflict with anything in there.

124
00:11:32,200 --> 00:11:35,520
So let's go ahead and do coordinate locations.

125
00:11:35,560 --> 00:11:36,870
Okay.

126
00:11:36,910 --> 00:11:41,320
And then back down here.

127
00:11:41,410 --> 00:11:46,300
Let's just do co-ordinate locations.

128
00:11:46,610 --> 00:11:53,310
OK now it won't conflict with our location array in this delegate.

129
00:11:53,410 --> 00:11:56,020
And let's just see what it's yelling at us.

130
00:11:56,050 --> 00:11:58,680
Yes I meant to spell it right.

131
00:11:58,960 --> 00:11:59,290
OK.

132
00:11:59,320 --> 00:12:05,260
So once we're done there we just inserted a new location into that array.

133
00:12:05,860 --> 00:12:12,850
And now we're getting yelled at when we add air when we're creating our run objects when we're adding

134
00:12:12,850 --> 00:12:19,180
it to realm it's yelling at us because it wants us to pass in that object so locations and then we have

135
00:12:19,180 --> 00:12:25,750
to add our our coordinate locations list.

136
00:12:25,870 --> 00:12:31,840
And now now we're done so we're adding all of our locations now to our run model.

137
00:12:31,990 --> 00:12:41,500
And now we can go and do the polyline overlay on the begin run visi.

138
00:12:41,680 --> 00:12:46,820
But let's first run this and see what happens.

139
00:12:56,080 --> 00:12:56,270
All right.

140
00:12:56,370 --> 00:13:01,440
So let's go ahead and start let's start Ron.

141
00:13:01,670 --> 00:13:06,400
And when we end this run okay.

142
00:13:06,880 --> 00:13:13,540
So our app didn't crash because we did our we didn't do ketches but look down here in our consulate's

143
00:13:13,540 --> 00:13:15,710
as air adding into realm.

144
00:13:15,910 --> 00:13:18,460
So what the heck is going on.

145
00:13:18,490 --> 00:13:21,410
So we're going to call this lesson done.

146
00:13:22,800 --> 00:13:28,830
And in the next lesson I'm going to teach you how to set up relm configurations for data migration.

147
00:13:28,830 --> 00:13:37,380
So we had to do some sort of configuration if you ever add or remove variables from a model in realm

148
00:13:37,380 --> 00:13:44,130
you have to prepare around to know to either remove it delete it rename it or like whatever you need

149
00:13:44,130 --> 00:13:49,210
to do in the migration and we'll get into the realm configurations in the next lesson.

150
00:13:49,320 --> 00:13:52,160
So we don't get this error with it not adding.

151
00:13:52,170 --> 00:13:59,820
So with this error that means that object didn't get added to our relm database and these other errors

152
00:13:59,820 --> 00:14:00,460
right here.

153
00:14:00,480 --> 00:14:06,090
These won't show up if you run the simul if you run this project on an actual device.

154
00:14:06,090 --> 00:14:07,880
This is all map kit stuff.

155
00:14:08,130 --> 00:14:12,360
And the simulator just causes these errors for whatever reason.

156
00:14:12,360 --> 00:14:19,080
So before we end this lesson let's go ahead and pull up our terminal and get ad period commit dash dash

157
00:14:19,950 --> 00:14:30,330
and let's see we added our locations list for creating a poly line overlay.

158
00:14:30,720 --> 00:14:31,420
Okay great.

159
00:14:31,440 --> 00:14:33,310
And I will see you in the next lesson.
