1
00:00:08,040 --> 00:00:12,880
Hey guys this is Caleb with slopes dot com and in this video we're going to set up our view controller

2
00:00:12,900 --> 00:00:16,190
that's going to allow us to make posts on feed visi.

3
00:00:16,230 --> 00:00:22,650
It's called create post Visi And we're also going to set up a model layer for messages and we're also

4
00:00:22,650 --> 00:00:26,060
going to set up the function that pushes our messages up to firebase.

5
00:00:26,160 --> 00:00:27,470
Very very cool stuff.

6
00:00:27,480 --> 00:00:32,750
Let's pull up in our X code project and let's go ahead and create post visi.

7
00:00:32,820 --> 00:00:34,830
So close the assistant editor.

8
00:00:34,830 --> 00:00:41,040
If you had it open from the last video and now what we're going to do is we're going to drag in a UI

9
00:00:41,070 --> 00:00:41,810
View Controller.

10
00:00:41,990 --> 00:00:42,310
OK.

11
00:00:42,360 --> 00:00:47,490
And I'm going to put it near my feet because those are kind of logically connected and I'm going to

12
00:00:47,490 --> 00:00:49,470
line them up something I do.

13
00:00:49,470 --> 00:00:50,260
Very cool.

14
00:00:50,370 --> 00:00:52,880
And now just like we've been doing.

15
00:00:52,890 --> 00:00:55,120
I'm going to go ahead and copy and paste this.

16
00:00:55,170 --> 00:00:59,110
And you know it's OK that I'm doing that because there are no outlets at the moment.

17
00:00:59,160 --> 00:01:01,080
If there were they could be stuck.

18
00:01:01,080 --> 00:01:05,520
They could be residual outlets that carry over and that can cause crashes and all kinds of unwanted

19
00:01:05,520 --> 00:01:06,390
behavior.

20
00:01:06,390 --> 00:01:10,680
So just check and make sure or just rebuild it from scratch if you want to.

21
00:01:10,680 --> 00:01:13,700
So now we're going to do is we're going to zoom on in here.

22
00:01:13,700 --> 00:01:17,850
We're going to set the background of this view controller it's just far too bright.

23
00:01:18,120 --> 00:01:20,860
Said it to be our light gray color.

24
00:01:20,970 --> 00:01:23,290
You can tell the difference between these two here.

25
00:01:23,450 --> 00:01:26,340
Set this label is not a constraint.

26
00:01:26,340 --> 00:01:27,500
Set the label to say.

27
00:01:27,500 --> 00:01:30,680
Post some thing.

28
00:01:31,170 --> 00:01:36,620
And of course we need to fix the constraint there so that the with is more like 200.

29
00:01:36,810 --> 00:01:37,730
That looks good.

30
00:01:37,800 --> 00:01:39,390
Although why didn't change

31
00:01:41,910 --> 00:01:43,320
oh that's because.

32
00:01:43,600 --> 00:01:43,840
Yeah.

33
00:01:43,860 --> 00:01:44,160
There we go.

34
00:01:44,160 --> 00:01:44,430
OK.

35
00:01:44,430 --> 00:01:45,820
Very cool.

36
00:01:45,840 --> 00:01:46,950
That looks great.

37
00:01:47,130 --> 00:01:53,450
And now it's centered but our view here has not been pinned anywhere.

38
00:01:53,460 --> 00:01:56,640
So give it a left top and right constraint of zero.

39
00:01:56,760 --> 00:01:59,150
It already has a height constraint of 70.

40
00:01:59,460 --> 00:02:00,330
Add those in.

41
00:02:00,390 --> 00:02:01,500
Now we're good.

42
00:02:01,710 --> 00:02:05,480
The cancel button is going to actually be over here as an X..

43
00:02:05,490 --> 00:02:10,520
And so what I'm going to do is I'm going to take note that it's 30 from the top 20 from the right.

44
00:02:10,530 --> 00:02:13,810
So I'm going to basically mirror that on the other side.

45
00:02:14,010 --> 00:02:15,710
I'm going to set it here.

46
00:02:16,110 --> 00:02:22,920
I'm going to remove the 20 from the right and instead I'm going to set it 20 from the left and it stays

47
00:02:22,920 --> 00:02:23,700
in place right there.

48
00:02:23,700 --> 00:02:28,610
Now remember we are centering these on each other so they'll always stay centered.

49
00:02:28,740 --> 00:02:31,150
But now we need to change the image of our button.

50
00:02:31,350 --> 00:02:38,700
So go ahead and set the image in the identity inspector or sorry the attributes inspector from compose

51
00:02:39,060 --> 00:02:41,200
to close.

52
00:02:41,310 --> 00:02:43,960
And that button will be used to close that controller.

53
00:02:44,040 --> 00:02:45,330
Very simple.

54
00:02:45,330 --> 00:02:47,740
Next we're going to drop in a UI image.

55
00:02:48,000 --> 00:02:52,060
And this is basically going to hold the profile image for the user.

56
00:02:52,320 --> 00:02:57,530
OK so make it a square let's make it 50 by 50 I think that's a good size.

57
00:02:57,780 --> 00:03:00,610
Maybe a little bigger maybe 60 by 60 would look.

58
00:03:01,080 --> 00:03:02,000
Yeah that's good.

59
00:03:02,830 --> 00:03:03,640
All righty.

60
00:03:03,700 --> 00:03:09,670
Now let's go ahead and pin this 20 from the top and we're going to use the margin here which is basically

61
00:03:09,670 --> 00:03:12,740
20 from the left and that's great.

62
00:03:12,760 --> 00:03:17,350
But now we need to give it a fixed height and width so that doesn't change on us either.

63
00:03:17,350 --> 00:03:18,640
Very cool.

64
00:03:18,640 --> 00:03:25,150
Next up let's add a label and that's going to hold the user names so we can see for what user are we

65
00:03:25,150 --> 00:03:29,520
posting drag on that label there drag it over to the far side.

66
00:03:29,560 --> 00:03:35,170
And let's go ahead let's pick at 20 from the left 0 to the margin which is the same thing as 20 from

67
00:03:35,170 --> 00:03:36,970
the right.

68
00:03:37,210 --> 00:03:37,780
And you know what.

69
00:03:37,780 --> 00:03:44,620
Let's give it a fixed height of 20 and now we need to go ahead and select both the image and the label

70
00:03:44,920 --> 00:03:49,140
and we're going click on the alignment button and give them vertical centers.

71
00:03:49,180 --> 00:03:52,200
Add one constraint and that looks great.

72
00:03:52,210 --> 00:03:59,350
Now let's go ahead and change the font of this as well as the color set the color to blue set the font

73
00:03:59,440 --> 00:04:01,530
to be Menlo like we've been doing.

74
00:04:01,780 --> 00:04:08,900
I wish you could set a system font like you can set a global tent or a Global Fund but you can't anyway.

75
00:04:09,010 --> 00:04:11,270
So that is Menlo 18.

76
00:04:11,380 --> 00:04:19,750
And let's just go ahead and do user at breakpoint dot com com like we've been doing and that looks awesome.

77
00:04:19,750 --> 00:04:26,110
So next up we need to add a UI text view in order to provide space for the user to post.

78
00:04:26,110 --> 00:04:29,300
So instead of using a text field we're going to use a text view.

79
00:04:29,410 --> 00:04:32,040
So they have a little bit more space to actually write something.

80
00:04:32,320 --> 00:04:40,230
So go ahead and type UI text view and let's drag that on K that looks good.

81
00:04:40,350 --> 00:04:46,080
Let's move it down here and let's just change a few things about it really fast.

82
00:04:46,080 --> 00:04:52,020
We want the background to be clear because we don't need that ugly white background.

83
00:04:52,020 --> 00:04:55,440
We want the font to be blue white or blue.

84
00:04:55,450 --> 00:04:58,980
Let's see which looks better blue versus white.

85
00:04:59,040 --> 00:05:00,530
I think Blue looks way cooler.

86
00:05:00,750 --> 00:05:01,770
Let's go with that.

87
00:05:01,980 --> 00:05:05,020
And let's set the font to also be Menlo.

88
00:05:05,720 --> 00:05:06,330
OK.

89
00:05:06,630 --> 00:05:09,210
And let's set it to be 18.

90
00:05:09,270 --> 00:05:09,770
Awesome.

91
00:05:09,780 --> 00:05:10,850
That looks very cool.

92
00:05:10,860 --> 00:05:17,640
Now we'll replace this Latin with say something here because if you look a text you does not inherently

93
00:05:17,910 --> 00:05:21,020
have a placeholder.

94
00:05:21,030 --> 00:05:26,210
So we're going to actually write a function later that when it detects that we're editing the place

95
00:05:26,210 --> 00:05:32,040
view it's going to go ahead or editing the text it's going to remove this text to make it blank it's

96
00:05:32,040 --> 00:05:33,560
just a really easy way to modify that.

97
00:05:33,570 --> 00:05:35,920
So that's cool that's in place.

98
00:05:35,940 --> 00:05:37,990
Say something here is showing.

99
00:05:38,160 --> 00:05:41,410
Now we need to add the button down here at the bottom.

100
00:05:41,460 --> 00:05:43,950
So go ahead and type UI button.

101
00:05:44,400 --> 00:05:50,190
We're going to drag on a button here and we're going to make this the width of the screen we're going

102
00:05:50,190 --> 00:05:53,480
to raise it up to be let's do 50.

103
00:05:53,640 --> 00:05:55,140
That's great.

104
00:05:55,140 --> 00:06:01,560
And let's go ahead and pin that to the bottom left and right and give it a fixed height of 50.

105
00:06:01,560 --> 00:06:07,020
We're going to also set the text color to be green K to indicate sending.

106
00:06:07,020 --> 00:06:08,520
Or you know pushing something out.

107
00:06:08,520 --> 00:06:09,710
Go green.

108
00:06:10,110 --> 00:06:14,580
And of course we want this to say Send Now the font.

109
00:06:14,580 --> 00:06:20,800
We can change to Menlo OK and let's make that size 18 Menlo.

110
00:06:21,000 --> 00:06:22,120
That looks good.

111
00:06:22,350 --> 00:06:28,810
Let's set the image to be the center image and you'll notice these greens are different.

112
00:06:29,130 --> 00:06:30,470
And it's too close.

113
00:06:30,480 --> 00:06:35,140
So let's go ahead and let's just maybe put two spaces there to give it some room.

114
00:06:35,160 --> 00:06:37,700
Let's go ahead and set the green here.

115
00:06:37,740 --> 00:06:41,820
We can actually use the eyedropper to choose the proper green for our text.

116
00:06:41,820 --> 00:06:43,440
That looks much better.

117
00:06:43,620 --> 00:06:50,490
And you'll notice though that the font went back so change it back to Menlo then lo 18 and mellow I

118
00:06:50,490 --> 00:06:51,720
guess the spaces are bigger.

119
00:06:51,720 --> 00:06:53,760
So just one space should do.

120
00:06:54,120 --> 00:06:59,070
And of course this button is the same color as the background so we should change it to be the darker

121
00:06:59,070 --> 00:07:01,020
gray so that it stands out.

122
00:07:01,020 --> 00:07:02,290
Very cool.

123
00:07:02,310 --> 00:07:07,850
We can also set our textfield here to be constrained 20 from the top 20 from the bottom.

124
00:07:07,860 --> 00:07:14,070
All we need to do is change it and then zero from the left and right and add those constraints and it's

125
00:07:14,130 --> 00:07:15,960
all perfectly in place.

126
00:07:15,960 --> 00:07:17,040
That looks awesome.

127
00:07:18,010 --> 00:07:19,330
Very very very cool.

128
00:07:19,540 --> 00:07:26,170
So next up we need to write a function that will allow us to upload a message to firebase So we're going

129
00:07:26,170 --> 00:07:29,830
to write the upload post function in our data service.

130
00:07:29,830 --> 00:07:30,380
OK.

131
00:07:30,640 --> 00:07:37,120
And that's going to allow us to just throw a message up to firebase and save it in the feed child in

132
00:07:37,120 --> 00:07:37,930
firebase.

133
00:07:37,930 --> 00:07:45,310
So let's go ahead and let's go to our data service and we'll write that first go down below create DB

134
00:07:45,310 --> 00:07:45,960
user.

135
00:07:46,360 --> 00:07:49,650
And we're going to write phunk upload post.

136
00:07:50,190 --> 00:07:50,820
OK.

137
00:07:51,100 --> 00:07:55,690
Now a post we need to think about what it's supposed to have it should have a message right.

138
00:07:55,690 --> 00:07:57,110
It should have words.

139
00:07:57,310 --> 00:08:03,190
We're going to need to link each post to each user who post it so we know who posted what.

140
00:08:03,490 --> 00:08:09,640
And we need to basically be able to tell is this message being posted in a group or is it being posted

141
00:08:09,640 --> 00:08:11,160
in the public feed.

142
00:08:11,200 --> 00:08:14,980
So let's go ahead and let's type out some of our parameters here.

143
00:08:14,980 --> 00:08:23,830
Upload post with message and message is going to be an internal parameter there for you I.D. meaning

144
00:08:23,830 --> 00:08:27,280
for the unique identifier you I.D. of type string.

145
00:08:27,280 --> 00:08:34,890
That's what we're using for are you IDs let's do with group key and the internal parameter would just

146
00:08:34,900 --> 00:08:36,760
be group key.

147
00:08:36,760 --> 00:08:40,300
And now that's optional because we may or may not have a group key.

148
00:08:40,300 --> 00:08:45,520
So we'll just go and put a question mark there and at the end we need to be able to understand is the

149
00:08:45,520 --> 00:08:47,020
send complete or is it not.

150
00:08:47,020 --> 00:08:48,820
So we're going to use a completion handler.

151
00:08:48,820 --> 00:08:52,170
So let's just say send complete.

152
00:08:52,510 --> 00:08:57,040
That's going to be the name of our handler and of course it's escaping because in order to get out of

153
00:08:57,040 --> 00:09:00,650
some of these firebase closures we need to be able to escape the value out of it.

154
00:09:01,060 --> 00:09:06,940
And of course we use a function when doing this and we will return an empty function because it doesn't

155
00:09:06,940 --> 00:09:08,400
matter what we return.

156
00:09:08,410 --> 00:09:13,100
All that matters is that we get a boolean back saying yes it was sent.

157
00:09:13,120 --> 00:09:14,220
No it was not.

158
00:09:14,230 --> 00:09:19,520
So for that we're going to use a parameter called status of type Boolean.

159
00:09:19,580 --> 00:09:21,330
OK simple as that.

160
00:09:21,340 --> 00:09:26,620
Next what we're going to do is we are basically going to see if the group key exists because that will

161
00:09:26,620 --> 00:09:28,740
really change where this message goes.

162
00:09:28,930 --> 00:09:36,640
So we'll see it will say if the group key is not equal to nil meaning if there is a group key We're

163
00:09:36,640 --> 00:09:45,270
going to go ahead and send this into the groups reference send to groups ref.

164
00:09:45,280 --> 00:09:52,660
Otherwise we're going to go ahead and we will pass it to the feed and we have access to the feed with

165
00:09:52,660 --> 00:09:53,770
this variable right here.

166
00:09:53,770 --> 00:10:01,390
So let's go ahead and call ref feed dot child and you know what there's a really cool thing called child

167
00:10:01,390 --> 00:10:02,840
by auto ID.

168
00:10:02,950 --> 00:10:06,840
This will generate a unique identifier for every message that comes in.

169
00:10:06,850 --> 00:10:12,550
That's what we want because we don't need to necessarily give it a specific name because the exact idea

170
00:10:12,550 --> 00:10:13,920
of the message doesn't matter.

171
00:10:13,930 --> 00:10:20,480
But inside we're going to be keeping the idea of the users so the child by Auto-ID function is perfect.

172
00:10:20,680 --> 00:10:27,050
And then inside of that child that we have made we're going to go ahead and update child values with

173
00:10:27,050 --> 00:10:28,190
the dictionary.

174
00:10:28,210 --> 00:10:31,780
Now we need to think what dictionary are we going to use.

175
00:10:31,840 --> 00:10:33,760
Let's go ahead and think about what a message needs.

176
00:10:33,760 --> 00:10:40,120
It needs content right it needs like some words and it needs a Sender ID so we know who sent it.

177
00:10:40,270 --> 00:10:43,090
So let's give those keys and values here.

178
00:10:43,120 --> 00:10:45,110
The first one I said was content.

179
00:10:45,520 --> 00:10:49,840
And of course the value for that is going to come from the message parameter we pass in.

180
00:10:50,050 --> 00:10:57,400
So go ahead and call message and then we need a Sender ID and the sender ID is going to be the ID that

181
00:10:57,400 --> 00:11:00,900
we pass in from wherever we call this function.

182
00:11:00,910 --> 00:11:07,870
Now as soon as that has been updated and firebase we can use our send complete handler to call.

183
00:11:07,870 --> 00:11:08,650
True.

184
00:11:09,010 --> 00:11:09,590
OK.

185
00:11:09,790 --> 00:11:13,630
Simple as that will come back to the groups later when we add groups we see stuff.

186
00:11:13,630 --> 00:11:18,400
But for now we're just focusing on the feed so upload Post is now ready to go.

187
00:11:18,550 --> 00:11:25,030
And so now we need to go into create post Visi And let's go ahead and let's send a message that will

188
00:11:25,030 --> 00:11:26,250
be really cool.

189
00:11:26,350 --> 00:11:28,330
So let's do it.

190
00:11:28,420 --> 00:11:32,020
We need to go where where we create post AVC.

191
00:11:32,080 --> 00:11:35,170
Oh and you know what we never created a new controller for that.

192
00:11:35,170 --> 00:11:36,360
So here it is.

193
00:11:36,370 --> 00:11:39,640
Let's go ahead and Right-Click new file.

194
00:11:39,730 --> 00:11:49,330
Touch class and we're going to call it create post Visi awesome so click Next click Create and it'll

195
00:11:49,360 --> 00:11:55,720
show up of course get rid of the boilerplate nastiness and go back to main storyboards so that we can

196
00:11:55,720 --> 00:11:57,130
set the identity.

197
00:11:57,130 --> 00:12:02,540
So choose the view controller choose the identity inspector and call create post AVC.

198
00:12:02,650 --> 00:12:03,650
Very cool.

199
00:12:03,850 --> 00:12:04,420
And you know what.

200
00:12:04,420 --> 00:12:08,840
This will actually not even show because we have not set up a Segway to present it.

201
00:12:08,920 --> 00:12:14,810
So we're going to click on our button here right click and drag to this view controller present Motilal

202
00:12:14,880 --> 00:12:19,430
is what we want because otherwise it'll use a navigation controller to show it.

203
00:12:19,430 --> 00:12:23,360
But we just want to present it mostly on top of the view that's fine.

204
00:12:23,750 --> 00:12:28,590
And when we select that button it's going to go ahead and present that view controller like we want.

205
00:12:28,850 --> 00:12:34,430
And now we can go ahead and set up some of our stuff in here so that when we type a message we can set

206
00:12:34,430 --> 00:12:38,530
up our Send button to upload our post and then automatically dismiss our view.

207
00:12:38,540 --> 00:12:39,630
It will be really cool.

208
00:12:39,740 --> 00:12:41,700
Let's go ahead and do that now.

209
00:12:42,080 --> 00:12:47,120
Open the assistant editor select Create post Visi and it should open it automatically.

210
00:12:47,120 --> 00:12:48,550
That's exactly what we want.

211
00:12:48,890 --> 00:12:51,930
And that to begin we're actually going to create some outlets here.

212
00:12:52,040 --> 00:13:01,860
One first for the profile image WIPs profile image next for the e-mail label.

213
00:13:02,330 --> 00:13:08,730
Then we need one for the text field text field.

214
00:13:08,750 --> 00:13:09,420
Awesome.

215
00:13:09,860 --> 00:13:13,700
And what else we need the send button here.

216
00:13:14,870 --> 00:13:24,150
And you know what we need an action for our close button close button was pressed.

217
00:13:24,380 --> 00:13:28,100
And beneath that we're going to go ahead and we're going to call or no.

218
00:13:28,100 --> 00:13:29,530
How about above that.

219
00:13:29,600 --> 00:13:35,840
Change it to an action and call send button was pressed.

220
00:13:35,840 --> 00:13:37,310
Very cool.

221
00:13:37,310 --> 00:13:40,580
Now the close button is easy we just call dismiss.

222
00:13:40,670 --> 00:13:41,480
True.

223
00:13:41,600 --> 00:13:41,860
You know what.

224
00:13:41,870 --> 00:13:45,800
That's way down there at the bottom when we give you some space here as you can see.

225
00:13:45,800 --> 00:13:46,860
We're called dismiss.

226
00:13:46,880 --> 00:13:47,440
True.

227
00:13:47,480 --> 00:13:53,120
And the completion we don't care if it's complete or not does not matter to us at this point.

228
00:13:53,120 --> 00:13:56,240
But what is really important is the send button.

229
00:13:56,240 --> 00:13:56,810
OK.

230
00:13:57,140 --> 00:13:59,050
Now I'm just clearing up some space here.

231
00:13:59,180 --> 00:14:00,310
And you know what.

232
00:14:00,340 --> 00:14:07,840
What we're going to do is we're going to set the send button so that it is good to go.

233
00:14:08,750 --> 00:14:14,090
So what we're going to do is we're going to set up an extension of you I textfield delegate so that

234
00:14:14,090 --> 00:14:18,570
we can tell when it edits so that we can remove say something here.

235
00:14:18,680 --> 00:14:28,160
So go ahead and create an extension of create post-PC of UI text field delegate and we can just call

236
00:14:28,520 --> 00:14:31,590
did begin editing.

237
00:14:32,120 --> 00:14:33,090
Very cool.

238
00:14:33,330 --> 00:14:34,070
Oh you know what though.

239
00:14:34,070 --> 00:14:34,700
This is wrong.

240
00:14:34,700 --> 00:14:38,680
We need text view delegate not textfield delegate sorry.

241
00:14:38,690 --> 00:14:41,300
They're very similar and I confuse them sometimes.

242
00:14:41,300 --> 00:14:43,200
So let's let's call that again.

243
00:14:43,220 --> 00:14:46,360
Did begin editing text view to begin editing.

244
00:14:46,640 --> 00:14:53,570
And if it begins editing set text view text to be equal to nothing that'll clear it out just like it's

245
00:14:53,630 --> 00:14:55,970
a placeholder.

246
00:14:55,970 --> 00:14:57,140
Very cool.

247
00:14:57,200 --> 00:15:02,660
So next up what we're going to do is we're going to go ahead and in order to actually set this delegate

248
00:15:02,660 --> 00:15:10,180
to work properly we need to call text view delegate equals self that makes this view controller the

249
00:15:10,180 --> 00:15:15,350
delegate for the text view and oh you know what I just realized we call it textfield didn't we.

250
00:15:15,350 --> 00:15:19,860
It's a text view that's going to cause us some issues.

251
00:15:19,880 --> 00:15:27,080
So of course we need to go in here and get rid of this and then reconnect it hopefully it'll let us

252
00:15:27,320 --> 00:15:31,350
might not interesting might need to go off and come back

253
00:15:34,360 --> 00:15:36,160
and go in here.

254
00:15:36,470 --> 00:15:37,660
Let's try again.

255
00:15:38,560 --> 00:15:39,420
It won't.

256
00:15:39,430 --> 00:15:39,850
Interesting.

257
00:15:39,850 --> 00:15:41,990
I wonder why OK.

258
00:15:42,010 --> 00:15:48,350
Well I guess we just do it again text view get rid of this old one that we no longer need.

259
00:15:48,430 --> 00:15:49,250
And we're good.

260
00:15:49,270 --> 00:15:50,060
OK.

261
00:15:50,320 --> 00:15:50,860
Very cool.

262
00:15:50,860 --> 00:15:53,920
So text viewer text equals blank.

263
00:15:53,980 --> 00:15:57,460
We have a text you hear the delegate has been set.

264
00:15:57,520 --> 00:16:02,410
Now let's go ahead and let's set up how we are going to send our message.

265
00:16:02,410 --> 00:16:08,500
So we need to verify though that there is some text so let's go ahead and type if text view text is

266
00:16:08,500 --> 00:16:15,580
not equal to nil meaning if there is text and you know what we should make sure that it doesn't just

267
00:16:15,580 --> 00:16:22,150
say say something here because that is text and it will pass if we don't run a check against it.

268
00:16:22,150 --> 00:16:24,100
So we need to say.

269
00:16:24,160 --> 00:16:31,300
And if text you that text is not equal to say something here.

270
00:16:31,870 --> 00:16:32,230
All right.

271
00:16:32,230 --> 00:16:34,200
We're checking against that as well.

272
00:16:34,450 --> 00:16:39,250
If that's good what we're going to do is for the time that it's sending We're going to disable the send

273
00:16:39,250 --> 00:16:45,810
button send button is enabled equals false.

274
00:16:45,820 --> 00:16:48,100
That way we can't double send or triple send.

275
00:16:48,100 --> 00:16:50,130
As soon as we press it it's disabled.

276
00:16:50,350 --> 00:16:58,960
Now we can call create post or upload posts from our data service data service instance dot upload post

277
00:16:59,320 --> 00:17:09,810
with message comes from whip's comes from text field or text view sorry text ok for you ID we're gonna

278
00:17:09,850 --> 00:17:16,060
go ahead and use our firebase off abilities to pull out the unique ID of this user.

279
00:17:16,060 --> 00:17:21,000
So we need to import firebase to get that.

280
00:17:21,120 --> 00:17:21,940
All righty.

281
00:17:22,000 --> 00:17:29,860
So we can go ahead and call off off current user and we can just grab the idea because we've already

282
00:17:29,860 --> 00:17:32,150
downloaded the user and authenticated them.

283
00:17:32,290 --> 00:17:32,920
That's great.

284
00:17:32,920 --> 00:17:35,440
So we can get that you that way.

285
00:17:35,440 --> 00:17:37,840
Perfect with group key.

286
00:17:37,840 --> 00:17:38,590
This is the feed.

287
00:17:38,590 --> 00:17:43,140
We don't need a group case we can pass in nyl and send complete.

288
00:17:43,210 --> 00:17:52,300
We can just press enter and in our completion handler assuming that it returns True we can say is complete.

289
00:17:52,300 --> 00:17:54,550
And now if is complete.

290
00:17:54,580 --> 00:18:01,960
Meaning if it is actually done sending we'll go ahead and call a self send button that is enabled and

291
00:18:01,960 --> 00:18:05,580
we'll re-enable it then we're going to dismiss the view controller.

292
00:18:05,590 --> 00:18:10,800
So we'll call self dot dismiss.

293
00:18:11,030 --> 00:18:14,390
Animated is true completion is nil.

294
00:18:14,500 --> 00:18:21,040
But what if the message does not send properly we can call it else and we can re-enable the button at

295
00:18:21,040 --> 00:18:23,000
that point as well.

296
00:18:23,320 --> 00:18:27,900
And then we're going to go ahead and print.

297
00:18:27,910 --> 00:18:31,750
There was an error.

298
00:18:31,880 --> 00:18:32,830
All right.

299
00:18:32,840 --> 00:18:33,610
So very cool.

300
00:18:33,620 --> 00:18:40,640
We are getting an error and it's going to tell me that the off right here if I go off the current user

301
00:18:41,000 --> 00:18:44,740
id it needs to be unwrapped because it's optional.

302
00:18:44,740 --> 00:18:49,530
It could change at any time if maybe the token expires.

303
00:18:49,670 --> 00:18:51,540
So it's optional so we unwrap it.

304
00:18:51,770 --> 00:18:58,580
And right now we are able to send a message let's build and run let's go test to see if our Send button

305
00:18:58,640 --> 00:19:03,980
is going to work properly we'll pull up our simulator here we'll pull up fire firebase as well so we

306
00:19:03,980 --> 00:19:08,280
can watch to see if it pops up in the right place select feed.

307
00:19:08,430 --> 00:19:11,590
There's our message say something here.

308
00:19:12,290 --> 00:19:15,390
Hey what's up.

309
00:19:15,450 --> 00:19:18,020
And it looks like our button was hidden by our keyboard.

310
00:19:18,020 --> 00:19:23,900
So I'm going to go ahead and I'll toggle the software a keyboard will make this button slide up so that

311
00:19:23,900 --> 00:19:25,300
it stays with the keyboard later.

312
00:19:25,310 --> 00:19:26,970
But for now let's press send.

313
00:19:27,890 --> 00:19:30,450
Looks like it went somewhere and hey look at that.

314
00:19:30,610 --> 00:19:36,880
The feed has shown up and there's our message sender ID got past our message content got passed and

315
00:19:36,880 --> 00:19:39,120
it has its own unique ID.

316
00:19:39,130 --> 00:19:40,120
Now this is amazing.

317
00:19:40,120 --> 00:19:44,070
We have now successfully been able to upload a message to firebase.

318
00:19:44,140 --> 00:19:48,880
It's saved online and we can now start to pull it down and show it in our feed.

319
00:19:48,880 --> 00:19:50,490
We'll get into that in a little bit.

320
00:19:50,590 --> 00:19:55,540
But for now we're going to actually write that function so that our button can slide up when the keyboard

321
00:19:55,540 --> 00:20:00,210
shows in our app because on an iPhone of course you can't use the MacBook keyboard.

322
00:20:00,250 --> 00:20:01,910
So we're going to set that up in the next video.

323
00:20:01,930 --> 00:20:03,510
Amazing job with this one.

324
00:20:03,520 --> 00:20:04,430
Let's head that way now.

