1
00:00:05,880 --> 00:00:06,660
What's up guys.

2
00:00:06,690 --> 00:00:12,300
I'm Jacob whatso with Debb slopes dot com if you remember where we left off in the last lesson.

3
00:00:12,300 --> 00:00:20,460
We created a list of co-ordinate locations for our run and we need this so we can get our our polyline

4
00:00:20,460 --> 00:00:22,300
rendered on our map view.

5
00:00:22,770 --> 00:00:30,090
And if you recall we ended up adding it down here in the location manager where we update locations

6
00:00:30,090 --> 00:00:39,240
we just inserted it into the list and we ran into a slight problem because we created a new location

7
00:00:39,240 --> 00:00:47,370
model with latitude and longitude and RELM wasn't saving anymore because we changed stuff in the database.

8
00:00:47,370 --> 00:00:53,780
And once you create the realm database you need to take care of data migrations and everything.

9
00:00:53,790 --> 00:00:56,830
The only other solution would be like deleting the app.

10
00:00:56,850 --> 00:01:02,760
So you make sure you delete around files and then they would create new ones at the beginning but obviously

11
00:01:02,760 --> 00:01:06,610
that's not a good solution for a production app.

12
00:01:06,630 --> 00:01:11,560
So in this lesson we're going to go over creating a realm configuration file.

13
00:01:11,580 --> 00:01:18,930
So first let's pull up our terminal and let's just create a new branch get check out flash B and this

14
00:01:18,930 --> 00:01:21,560
will be less than 17.

15
00:01:21,570 --> 00:01:22,020
All right.

16
00:01:22,020 --> 00:01:22,530
Great.

17
00:01:22,530 --> 00:01:25,770
And now we can go ahead and get started.

18
00:01:25,770 --> 00:01:33,300
We won't commit anything yet because we haven't done a thing but let's go ahead and add a new file to

19
00:01:33,300 --> 00:01:35,810
our utility folder.

20
00:01:35,820 --> 00:01:45,930
It's going to be a swift file Iowas swift and let's call this our realm config just like that.

21
00:01:45,930 --> 00:01:48,130
That's perfect.

22
00:01:48,130 --> 00:01:49,590
All right.

23
00:01:50,100 --> 00:01:52,710
And we need to import relm Swift.

24
00:01:52,710 --> 00:02:00,390
So let's go ahead and do that and then we'll just call this class relm config.

25
00:02:00,390 --> 00:02:01,950
Just like our file name

26
00:02:04,640 --> 00:02:06,060
ok now.

27
00:02:06,120 --> 00:02:16,090
Well all we need to do is basically make a like a static variable and we're going to use all of realms

28
00:02:17,760 --> 00:02:22,740
configurations so we're gonna have to we have to set up the path where the realm database is going to

29
00:02:22,740 --> 00:02:28,440
be saved and then we also have to keep track of the scheme number.

30
00:02:28,440 --> 00:02:33,720
So every time you make a model change you would increase the scheme number in the configuration folder

31
00:02:34,170 --> 00:02:39,390
and then you make a area that you would take care of all your data migrations.

32
00:02:39,390 --> 00:02:46,380
We're not going to get into data migrations in this course but in a later more advanced course we'll

33
00:02:46,380 --> 00:02:48,250
probably dive into them a little more.

34
00:02:48,540 --> 00:02:55,580
So why don't we get started and let's just make a static variable so static var and we will call this

35
00:02:55,830 --> 00:03:04,860
run data config and it's going to be of type realm that configuration and then go ahead and do opening

36
00:03:04,860 --> 00:03:08,070
and closing brackets or curly braces.

37
00:03:08,640 --> 00:03:20,340
And let's see the first first couple of things that we're going to need to do is we need to have a path

38
00:03:20,340 --> 00:03:22,370
where we want our database saved.

39
00:03:22,530 --> 00:03:31,950
So let's make a constant and we'll call it relm path and we're going to just basically save it in the

40
00:03:31,950 --> 00:03:34,020
document directory of the phone.

41
00:03:34,020 --> 00:03:40,630
So we'll just go ahead and say call file manager default.

42
00:03:41,100 --> 00:03:42,840
You are Elle's right.

43
00:03:42,840 --> 00:03:47,440
And this is going to be in the document directory.

44
00:03:47,580 --> 00:03:48,840
So let's do that.

45
00:03:49,020 --> 00:03:56,310
And then we need it to be in our user domain mask.

46
00:03:56,310 --> 00:03:56,710
Right.

47
00:03:56,730 --> 00:04:06,780
And we're going to just pull up the first slot in this array and we're going to go ahead and make a

48
00:04:06,780 --> 00:04:14,380
new appending path and we're just going to call it our realm log which will make a.

49
00:04:14,630 --> 00:04:22,120
So we'll call it we'll make it constant for it in a second realm relm run log.

50
00:04:26,620 --> 00:04:27,180
OK.

51
00:04:27,210 --> 00:04:29,190
So we need to make a constant for this.

52
00:04:29,190 --> 00:04:32,390
And you know relm run log let's make it relm

53
00:04:35,270 --> 00:04:38,680
run loops run config.

54
00:04:38,690 --> 00:04:46,610
That makes more sense since this is the directory to our entire database.

55
00:04:47,010 --> 00:04:50,660
And then all we need to do down here is do.

56
00:04:51,760 --> 00:04:56,550
I'm sorry I went into our Constans folder and then let's go ahead had to make a constant variable called

57
00:04:56,550 --> 00:05:10,040
relm underscore run underscore config and then just name this realm run config and just make it a string.

58
00:05:10,440 --> 00:05:11,360
Save that.

59
00:05:11,370 --> 00:05:14,390
And let's go back to our room config folder.

60
00:05:14,400 --> 00:05:14,670
All right.

61
00:05:14,670 --> 00:05:21,120
So now we have our path where we can save our items and now we need to create our our configuration

62
00:05:21,120 --> 00:05:21,840
variable.

63
00:05:21,990 --> 00:05:31,320
So we need a we'll just do we'll call this config and this is going to be equal to relm dot configuration

64
00:05:31,650 --> 00:05:34,230
and we need to do an opening parentheses

65
00:05:36,690 --> 00:05:40,090
around it and we'll do close in parentheses right away.

66
00:05:42,480 --> 00:05:52,960
And now all we need to do is we need to declare our file you are all so open file you are a lot of this

67
00:05:52,960 --> 00:05:58,450
won't autocomplete that's a little irritating and this is going to be our realm path that we just created

68
00:05:59,080 --> 00:06:00,920
and then go ahead and hit Khama.

69
00:06:01,360 --> 00:06:09,640
And we also need a scheme a scheme a version and let's see Scheme

70
00:06:12,260 --> 00:06:17,990
version and here you would just put a number in and we'll start at zero.

71
00:06:18,680 --> 00:06:23,900
And then so every time you would actually update your models you would have to increase this number

72
00:06:24,350 --> 00:06:30,800
and that knows that the new scheme is different than the one saved in the realm database on your on

73
00:06:30,800 --> 00:06:32,060
your local drive.

74
00:06:32,330 --> 00:06:38,920
And if that's different you can run then run migration code where if you wanted to change.

75
00:06:39,110 --> 00:06:44,880
I don't know a integer variable to a double or you could go through all that and instead of just creating

76
00:06:44,900 --> 00:06:50,960
a new element you could actually replace the current one there and then we need to call our migration

77
00:06:50,960 --> 00:06:51,820
Block.

78
00:06:52,190 --> 00:06:58,120
And this is this is where all the migration data would be drawn.

79
00:06:58,550 --> 00:07:01,810
And you just do it by migration.

80
00:07:01,940 --> 00:07:04,070
And then our old schema

81
00:07:06,770 --> 00:07:10,530
version in.

82
00:07:10,620 --> 00:07:12,230
So it's a closure.

83
00:07:12,230 --> 00:07:15,270
All right.

84
00:07:15,520 --> 00:07:18,760
And here is where you would do an if statement.

85
00:07:18,760 --> 00:07:20,440
And so if the old schema

86
00:07:23,030 --> 00:07:35,070
old Scheme version is less than our current schema version which is zero will put 0 in and then you

87
00:07:35,070 --> 00:07:44,790
know curly braces open and close in and just leaving this blank blank here nothing to do.

88
00:07:44,790 --> 00:07:56,970
Relm will automatically detect new properties and remove properties.

89
00:07:56,970 --> 00:07:58,030
So that's pretty cool.

90
00:07:58,050 --> 00:08:01,500
So like we just added the Location property right.

91
00:08:01,540 --> 00:08:07,650
So if we removed them as well as long as our schema number is different than the previous version it

92
00:08:07,650 --> 00:08:12,550
will just replace either add elements or properties or delete properties.

93
00:08:12,780 --> 00:08:18,600
The only time you actually have to do data in here is if your changing like types and you have a more

94
00:08:18,600 --> 00:08:25,830
complicated migration which could be a target topic in its own and will probably will probably get there

95
00:08:25,830 --> 00:08:29,160
because we do have to do that quite a bit and the depth slopes up.

96
00:08:29,220 --> 00:08:32,580
So I think this will be a really good thing to go over.

97
00:08:32,700 --> 00:08:37,360
It's just a little out of the scope for this beginner course.

98
00:08:38,010 --> 00:08:43,200
And then we're just going to bring those parentheses up in front of the bracket and then underneath

99
00:08:44,160 --> 00:08:54,480
your config variable here all we're going to do is return it return config and it should stop yelling

100
00:08:54,480 --> 00:08:54,930
at us.

101
00:08:54,930 --> 00:08:56,190
There we go.

102
00:08:56,190 --> 00:08:58,050
So now we have this all done.

103
00:08:58,050 --> 00:09:05,610
This is our configuration we stated where we're saving our database and then we also created our config

104
00:09:05,610 --> 00:09:06,430
file.

105
00:09:06,690 --> 00:09:21,400
So now if we go to let's see our run model and we have to find one of our rights like right here.

106
00:09:21,590 --> 00:09:28,730
So right here where we just call relm that's just going go into the default setup which is fine in most

107
00:09:28,730 --> 00:09:31,860
cases until you start updating your models and everything.

108
00:09:32,000 --> 00:09:40,310
And you can also do encrypted relm databases which we do in our app and that would actually prevent

109
00:09:40,310 --> 00:09:45,380
people from opening up the database file and been able to read stuff which will probably be covered

110
00:09:45,380 --> 00:09:47,380
in another target topic as well.

111
00:09:47,530 --> 00:09:54,350
But for calling our configuration file that we just created you would just do realm and then go down

112
00:09:54,350 --> 00:09:56,760
to this one that says configuration.

113
00:09:57,650 --> 00:10:05,480
And now all we have to do is call our around config that swift file and then call our run data config

114
00:10:08,010 --> 00:10:09,180
and save that.

115
00:10:09,200 --> 00:10:16,050
And now instead of calling just the default relm set up we're actually calling our relm config file

116
00:10:16,050 --> 00:10:18,540
here which is pretty cool.

117
00:10:19,080 --> 00:10:21,660
And now I'm just going to copy and paste this.

118
00:10:22,050 --> 00:10:25,720
And we want to do it down here in our get all Ran's as well.

119
00:10:25,740 --> 00:10:31,110
If we don't update this it won't actually find our runs because we're saving things to a different location

120
00:10:31,110 --> 00:10:34,950
now and then let's see.

121
00:10:34,950 --> 00:10:40,800
I believe our other one we don't have anything in our location object because we have a reference to

122
00:10:40,800 --> 00:10:42,640
it right here with our list.

123
00:10:43,110 --> 00:10:45,540
So that should be good.

124
00:10:45,600 --> 00:10:52,750
And now let's go ahead and run this and we'll see if our run actually can save.

125
00:10:52,770 --> 00:10:54,370
We have a weird error.

126
00:10:54,580 --> 00:10:57,820
Oh I need to do a pod install.

127
00:10:59,920 --> 00:11:01,730
OK let's run this again.

128
00:11:05,570 --> 00:11:08,420
Write So you want to allow that.

129
00:11:08,870 --> 00:11:11,060
And now if we go ahead and press Ron

130
00:11:15,960 --> 00:11:23,700
make sure that we're in our city run so de-bug location city run and you see our stuff up in

131
00:11:29,570 --> 00:11:31,850
it looks like we're driving a car.

132
00:11:35,050 --> 00:11:38,990
Doesn't like something City.

133
00:11:39,000 --> 00:11:39,630
Ron

134
00:11:44,810 --> 00:11:46,920
we'll worry about that later.

135
00:11:49,600 --> 00:11:51,280
All right let's go ahead and our Ron

136
00:11:54,460 --> 00:11:59,550
and we did not get around mayor this time down here where it says unable to write around.

137
00:11:59,620 --> 00:12:00,860
So that's great.

138
00:12:00,940 --> 00:12:04,850
And you see that our last run popped up so that's a good sign.

139
00:12:05,110 --> 00:12:07,530
And we also should have our run Lague

140
00:12:12,230 --> 00:12:13,460
and we have a run log.

141
00:12:13,490 --> 00:12:16,070
So that's really sweet.

142
00:12:16,100 --> 00:12:18,620
Let's go ahead and stop that.

143
00:12:18,890 --> 00:12:21,360
And I'm going to call this part done.

144
00:12:21,380 --> 00:12:26,570
And in our next lesson we will be adding our polyline rendering to the map.

145
00:12:26,600 --> 00:12:28,250
So that'll be really cool.

146
00:12:28,250 --> 00:12:29,850
So I will see you guys next time.
