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