1
00:00:04,900 --> 00:00:09,130
Welcome back to class ladies and gentleman joining me here with those slopes dot com.

2
00:00:09,370 --> 00:00:14,100
And we are about to embark on the final stage of our Random app.

3
00:00:14,320 --> 00:00:15,540
We've done a whole lot.

4
00:00:15,540 --> 00:00:17,950
Up till this point in the previous two courses.

5
00:00:18,130 --> 00:00:24,220
So if you have not taken both of those I would highly recommend going back and starting with the fire

6
00:00:24,220 --> 00:00:29,470
store of course followed up with fire part two right because we're going to be building off of the app

7
00:00:29,470 --> 00:00:31,600
that we built in those two courses.

8
00:00:31,600 --> 00:00:31,880
All right.

9
00:00:31,880 --> 00:00:35,140
And yes what are we going to do in this course.

10
00:00:35,140 --> 00:00:42,190
Well if we check out our mockup that you have available in the assets for for this lesson then you will

11
00:00:42,190 --> 00:00:46,430
see that we are going to be adding some more functionality.

12
00:00:46,630 --> 00:00:52,240
So up until this point we've been able to create posts and add comments.

13
00:00:52,270 --> 00:01:00,310
Now we are going to learn about how to delete our store documents and collections as well as learn some

14
00:01:00,310 --> 00:01:03,910
more advanced fire store security rules.

15
00:01:03,910 --> 00:01:06,670
All right so that's going to be the focus of this target topic.

16
00:01:06,910 --> 00:01:14,890
And so you'll see here that we have this indicator here next to some of the posts and what this is is

17
00:01:14,940 --> 00:01:21,450
this is a little menu that can pop up if it is a comment or a post that you wrote.

18
00:01:21,520 --> 00:01:22,010
OK.

19
00:01:22,240 --> 00:01:26,190
So if you did not write it right now J.B. is logged in.

20
00:01:26,330 --> 00:01:30,580
And so J.B. wrote these posts and so the indicator is showing here.

21
00:01:30,580 --> 00:01:37,230
But for Bela's posts it is not showing because we cannot alter her posts.

22
00:01:37,280 --> 00:01:37,520
Right.

23
00:01:37,600 --> 00:01:45,460
So you can only delete or in the case of comments you can see here that comments can delete or edit

24
00:01:45,490 --> 00:01:46,060
the comment.

25
00:01:46,090 --> 00:01:53,970
And over here we have a new view controller where we're able to actually edit comments.

26
00:01:54,100 --> 00:01:56,350
So it's going to be pretty cool stuff.

27
00:01:56,350 --> 00:02:00,130
So you're excited so let's jump right in.

28
00:02:00,190 --> 00:02:03,550
So I mentioned that we have some assets available.

29
00:02:03,550 --> 00:02:06,270
So let's go ahead and check those out.

30
00:02:06,280 --> 00:02:13,260
We have a folder of assets and I couldn't really decide on how I wanted that little indicator to look.

31
00:02:13,270 --> 00:02:17,470
So you got up you got several options you've got four different styles.

32
00:02:17,560 --> 00:02:21,470
Some are thicker and in two different colors orange and the dark gray.

33
00:02:21,580 --> 00:02:21,990
All right.

34
00:02:22,120 --> 00:02:29,980
Just square and add those when open the assets and then drag all of those in and you'll be able to kind

35
00:02:29,980 --> 00:02:37,150
of see the different styles for that button that you are able to pick for yourself.

36
00:02:37,150 --> 00:02:43,660
So whichever style you are most inclined to pick go right ahead and let's see here what else do we have

37
00:02:43,660 --> 00:02:45,950
in that folder.

38
00:02:46,000 --> 00:02:52,090
We have the mock up that we were just looking at as well as the starter code.

39
00:02:52,270 --> 00:02:57,380
If you haven't taken the previous two and it you just want to start right here I don't recommend it

40
00:02:57,730 --> 00:03:03,430
but if you do or if you kind of just want to make sure that you are starting at the exact same point

41
00:03:03,430 --> 00:03:08,560
as I am then you can use the starter code right here as well.

42
00:03:08,560 --> 00:03:14,860
All right so now that we have our new assets in here and we've kind of talked a little bit about what

43
00:03:14,860 --> 00:03:18,290
we want to do let's think about how that's going to work in code.

44
00:03:18,370 --> 00:03:18,900
Okay.

45
00:03:19,060 --> 00:03:28,630
So just coming back here again looking at this we want it so that we can know if a thought or a comment

46
00:03:29,080 --> 00:03:31,080
is owned by the user.

47
00:03:31,300 --> 00:03:36,970
So right now if we take a look at our thought and common models there's not really any way of knowing

48
00:03:36,970 --> 00:03:37,340
that.

49
00:03:37,420 --> 00:03:40,720
So we're going to have to do a little bit of modification here.

50
00:03:40,720 --> 00:03:48,700
All right so each thought in each comment we need to add a new property that will hold the user's ID

51
00:03:49,720 --> 00:03:51,780
at the time that it is created.

52
00:03:52,180 --> 00:03:55,500
So let's go to an ad that will just go ahead and add it to both.

53
00:03:55,500 --> 00:03:57,200
So let's start with thought here.

54
00:03:57,230 --> 00:04:07,090
So when I say private set var and when I say user id and this is a string.

55
00:04:07,930 --> 00:04:14,650
And when we initialize we are going to do as well from say user id type string.

56
00:04:15,220 --> 00:04:24,270
And then we're going to say self-taught user ID is equal to user ID and that looks good.

57
00:04:24,300 --> 00:04:29,350
Then on here in the Parus we're going to need to parse it out but we're going to need a new constant.

58
00:04:29,410 --> 00:04:32,680
Someone create a new constant here and this is going to be a new field.

59
00:04:32,740 --> 00:04:45,610
So when I say let user underscore ID equal user id go and jump back into thought and we'll say that

60
00:04:46,210 --> 00:04:47,860
user id equal.

61
00:04:48,240 --> 00:04:59,320
And that is data and the constant user ID as a string or else will just to empty string.

62
00:04:59,350 --> 00:05:03,960
Right now we're going to need to adjust our constructor here for the thought.

63
00:05:03,970 --> 00:05:09,510
So when I say user ID and that is user ID.

64
00:05:09,820 --> 00:05:11,780
There we go.

65
00:05:12,330 --> 00:05:12,580
Right.

66
00:05:12,580 --> 00:05:15,710
So our class is all taken care of.

67
00:05:16,090 --> 00:05:21,220
But now when we actually create this thought We need to modify that as well.

68
00:05:21,220 --> 00:05:28,750
So here in the ad thought Visi lets see here down here where we say post button tappet we are going

69
00:05:28,750 --> 00:05:33,190
to need to add the user id to the data that is saved to the document.

70
00:05:33,190 --> 00:05:39,820
So Im just going to do a comma and say user lets see here underscore.

71
00:05:40,040 --> 00:05:43,480
I am not sure why the autocomplete is not working but there we go.

72
00:05:43,810 --> 00:05:57,220
And to get the user id we just check out our firebase instance and we say off of that current user you

73
00:05:57,270 --> 00:05:58,280
ID.

74
00:05:58,960 --> 00:06:06,430
And since that is an optional we will just provide an empty string and we are going to do the same thing

75
00:06:06,700 --> 00:06:11,730
to our comment and output file.

76
00:06:11,920 --> 00:06:17,620
Now having already gone through this process I also know that we are going to need the document ID in

77
00:06:17,620 --> 00:06:19,780
the future so let's go ahead and add that as well.

78
00:06:19,780 --> 00:06:29,320
So we're going to add two properties we're going to add the document ID which is of type string as well

79
00:06:29,320 --> 00:06:30,460
as the

80
00:06:34,650 --> 00:06:37,840
user id which is also a string.

81
00:06:38,070 --> 00:06:45,770
All right then we're going to need to add those to the initialiser Yes we're going to say document ID

82
00:06:45,930 --> 00:06:54,080
of type string and user id of type string that should be a colon there we go.

83
00:06:54,300 --> 00:07:04,340
And then add them down here's when we say so that document is equal to document the self and user ID

84
00:07:04,340 --> 00:07:06,590
is equal to user ID.

85
00:07:06,950 --> 00:07:10,750
And then we're going to need to parse out those two new properties.

86
00:07:10,840 --> 00:07:22,550
I'm going to say let document the equal document dot document ID so together document ID we just get

87
00:07:22,550 --> 00:07:27,020
the document that we are looking through and access the document ID property.

88
00:07:27,410 --> 00:07:27,930
OK.

89
00:07:28,040 --> 00:07:41,330
And then we're going to say that user id equal data and the constant key user ID has a string else just

90
00:07:41,330 --> 00:07:42,300
an empty string.

91
00:07:42,650 --> 00:07:45,840
And then we do just our initialiser here.

92
00:07:45,840 --> 00:07:59,840
So this is going to be a document ID is document ID and that user ID is the user id right so that is

93
00:07:59,840 --> 00:08:03,080
taking care of our class is complete.

94
00:08:03,080 --> 00:08:06,520
Now we need to go to where the comments are created.

95
00:08:06,530 --> 00:08:14,570
So here in comments we see and let's see here add comment tapped her going to need to update our set

96
00:08:14,720 --> 00:08:15,850
data right here.

97
00:08:15,850 --> 00:08:19,910
So all right so we are going to be adding the user ID.

98
00:08:20,240 --> 00:08:25,950
And again we just access that by off of the current user data.

99
00:08:26,390 --> 00:08:33,900
You id instance is optional We will provide a default empty string.

100
00:08:34,240 --> 00:08:34,420
All right.

101
00:08:34,660 --> 00:08:35,880
That looks good.

102
00:08:36,350 --> 00:08:43,580
So now when we save to our fire store database has to go and take a look at that our documents for our

103
00:08:43,580 --> 00:08:49,220
thoughts and our comments will have the field for user ID.

104
00:08:49,220 --> 00:08:53,090
Now if you're using the same database that you used in the previous two courses and you have a bunch

105
00:08:53,090 --> 00:08:59,180
of testing here you may want to just delete all of your prior documents and start over so that your

106
00:08:59,180 --> 00:09:02,630
new documents have this information.

107
00:09:02,630 --> 00:09:06,280
To do that you can click right here and say delete all documents.

108
00:09:06,740 --> 00:09:11,990
And that way you'll just be starting from a clean slate with all of your data all of your documents

109
00:09:11,990 --> 00:09:14,490
having all of the data that it needs.

110
00:09:14,750 --> 00:09:22,970
All right so now that are classes even have the capability of knowing which user they belong to.

111
00:09:22,970 --> 00:09:26,030
Let's go ahead and add that image button.

112
00:09:26,060 --> 00:09:37,830
Someone go into main storyboard and for our thoughts sell here I'm going to go ahead and drag in an

113
00:09:37,850 --> 00:09:38,680
image.

114
00:09:38,900 --> 00:09:42,970
You can I'm just going to drop that are right here.

115
00:09:43,040 --> 00:09:47,910
Resize that.

116
00:09:48,530 --> 00:09:51,060
And let's go ahead and set an image for it.

117
00:09:51,320 --> 00:09:55,430
And like I said you can pick any of the four images that you like.

118
00:09:55,440 --> 00:10:03,640
We have this one which has orange and it has a slightly thicker stroke on the Hondius circles.

119
00:10:03,740 --> 00:10:05,510
We have that in dark.

120
00:10:05,540 --> 00:10:13,360
We have that in and then we have one that is thinner stroke and that in dark as well.

121
00:10:13,520 --> 00:10:17,250
I think I'm going to go with this one here.

122
00:10:17,720 --> 00:10:23,690
And then I'm going to I just kind of put this up here and we're going to control and drag it to the

123
00:10:23,690 --> 00:10:30,550
time stamp label and centered vertically and then we'll just set it to 14 from the right.

124
00:10:30,620 --> 00:10:32,380
That looks pretty good to me.

125
00:10:32,420 --> 00:10:33,570
All right there we go.

126
00:10:33,860 --> 00:10:37,540
And now let's go ahead and add it to our thought.

127
00:10:37,550 --> 00:10:43,790
So I'm going to hold option and click on thought cell to open it up in our assistant editor and we go

128
00:10:44,060 --> 00:10:45,640
and I'm going to add this.

129
00:10:45,660 --> 00:10:46,830
I yell it here.

130
00:10:46,860 --> 00:10:59,120
That's when control and drag from there ends say options menu and say connect and then we'll close that

131
00:10:59,650 --> 00:11:03,130
and we're going to do the same thing on our comments cell here.

132
00:11:03,300 --> 00:11:16,560
So it's going to drag an image view and a resize that to about 30 by 30 is going to resize that here

133
00:11:16,680 --> 00:11:18,060
30 by 30.

134
00:11:18,420 --> 00:11:22,610
And then we're going to change the image too.

135
00:11:22,990 --> 00:11:30,720
I'm going to choose Options image dark and then we're going to just drag that up here and zoom in here.

136
00:11:30,900 --> 00:11:33,560
I'm going to close this bottom paint as well.

137
00:11:34,230 --> 00:11:41,140
Want to control drag from the options image to the time stamp label and say center vertical and and

138
00:11:41,140 --> 00:11:46,710
then we'll add a chilling space and that looks fine we'll say about 11 that looks good.

139
00:11:47,580 --> 00:11:54,000
All right so now we have our project kind of set up we've modified our thought and comment classes.

140
00:11:54,000 --> 00:11:59,460
We've added the options of menus to our comment and thought cells.

141
00:11:59,610 --> 00:12:05,820
And in the next lesson we are going to work a little bit more in the code and logic adding some protocols

142
00:12:05,850 --> 00:12:10,590
and delegates and yes we're going to be working on some cool stuff here so I'll see you in the next

143
00:12:10,590 --> 00:12:11,110
one.
