1
00:00:07,670 --> 00:00:13,130
Hey everybody this is Caleb with slopes com and in this video we're going to set up a model layer in

2
00:00:13,130 --> 00:00:19,580
order to create messages which of course as you probably know a message has to have content words and

3
00:00:19,580 --> 00:00:24,130
it should have a way to identify the sender and in our case we're going to use our unique ID.

4
00:00:24,290 --> 00:00:29,150
So we're first going to create that message model and then after that we're going to create a function

5
00:00:29,510 --> 00:00:36,530
that's going to download all of the feed images that's going to download all of the feed messages from

6
00:00:36,530 --> 00:00:41,280
firebase and then we'll set it up to display in our table view really cool stuff.

7
00:00:41,300 --> 00:00:47,360
So pull open that XCode project and we're going to start by creating that message model by right clicking

8
00:00:47,360 --> 00:00:50,060
on model and creating a new file.

9
00:00:50,270 --> 00:00:50,660
Next.

10
00:00:50,660 --> 00:00:57,050
Go ahead and type or select a swift file and we'll just call this message press create.

11
00:00:57,380 --> 00:01:00,270
And now we're going to create our message class.

12
00:01:00,290 --> 00:01:01,790
So go ahead and type.

13
00:01:01,790 --> 00:01:08,840
Class message and now we need to think every message needs two things content and a way to identify

14
00:01:08,840 --> 00:01:09,480
the sender.

15
00:01:09,500 --> 00:01:16,970
In our case a Sender ID so to do that we're going to create some properties to hold just those things.

16
00:01:16,970 --> 00:01:19,890
So we're going to use data encapsulation like before.

17
00:01:19,910 --> 00:01:28,040
So go ahead and create two private variables private var underscore content of type string.

18
00:01:28,490 --> 00:01:35,630
And we're also going to type private var Sender ID of type string.

19
00:01:35,630 --> 00:01:41,090
Now we're going to create two public variables for the same ones but remove the underscores and set

20
00:01:41,120 --> 00:01:44,690
these ones to be able to display the proper information.

21
00:01:44,690 --> 00:01:49,510
So go ahead and type var content of type string.

22
00:01:49,570 --> 00:01:55,160
Get some curly brackets and we're going to just return the value of content.

23
00:01:55,390 --> 00:01:55,920
OK.

24
00:01:56,210 --> 00:02:02,430
Now go ahead and call var Sender ID of type string.

25
00:02:02,750 --> 00:02:06,490
And we're going to return the Sender ID.

26
00:02:06,500 --> 00:02:10,850
Now we're going to do is we're going to set up an initializer so that whenever we want to create an

27
00:02:10,910 --> 00:02:16,790
object of message we're going to initialize that message with the proper content and with the proper

28
00:02:16,790 --> 00:02:17,490
Sender ID.

29
00:02:17,510 --> 00:02:21,110
So go ahead and call in it and the parameters we're going to pass it.

30
00:02:21,110 --> 00:02:23,920
One our content of type string.

31
00:02:24,090 --> 00:02:25,010
And guess.

32
00:02:25,010 --> 00:02:30,020
Can you guess I can guess its sender ID of type string.

33
00:02:30,410 --> 00:02:39,710
So when once we initialize this object with content and ascender ID we should set self datt content

34
00:02:40,250 --> 00:02:46,160
to be equal to content and that will basically give us the ability to access this content variable because

35
00:02:46,760 --> 00:02:52,520
we can privately set the value of content here but nothing else can and our and our app only through

36
00:02:52,520 --> 00:02:57,800
our initialiser Can we set the value of content and then the public variable content can be accessed

37
00:02:57,800 --> 00:03:00,650
by underscore private variable content.

38
00:03:00,650 --> 00:03:05,960
So its a really cool way to encapsulate the data and hide it so that it's only accessible by the classes

39
00:03:05,960 --> 00:03:07,960
you want it to be accessible to.

40
00:03:08,270 --> 00:03:14,410
So self-taught underscore Sender ID is equal to the sender ID we pass it at initialization.

41
00:03:14,510 --> 00:03:15,020
That's it.

42
00:03:15,050 --> 00:03:15,890
That's our message.

43
00:03:15,890 --> 00:03:17,990
Class it's super duper easy.

44
00:03:18,050 --> 00:03:24,320
And now we can actually create a function to pull down all of the message data from the feed on firebase

45
00:03:24,650 --> 00:03:30,650
pass all of the information into an instance of message and append that to an array of messages that

46
00:03:30,650 --> 00:03:32,480
we will then display in our table view.

47
00:03:32,560 --> 00:03:33,680
It's really really cool stuff.

48
00:03:33,680 --> 00:03:38,840
So let's go back to our data service and let's write a new function below.

49
00:03:38,930 --> 00:03:47,810
We're going to call it get all feed messages so go ahead and type phunk get all feed messages and we

50
00:03:47,810 --> 00:03:49,660
need to think about what we need to do.

51
00:03:49,790 --> 00:03:55,400
We're going to call or we're going to try to pull data from our feed reference and we're going to pull

52
00:03:55,400 --> 00:03:57,850
it down when we're all the way done.

53
00:03:58,010 --> 00:04:04,700
We need to be able to pass the data that we download out of our closure and the only way we can do that

54
00:04:05,090 --> 00:04:06,620
is through an escaping closure.

55
00:04:06,620 --> 00:04:11,150
So using a handler like we have been using is a really great way to do that.

56
00:04:11,160 --> 00:04:16,220
So let's go ahead and let's call handler and it's going to be escaping.

57
00:04:17,270 --> 00:04:21,830
And then what we're going to do is we're going to create a function and this function is where we're

58
00:04:21,830 --> 00:04:23,610
going to pass in our values.

59
00:04:23,630 --> 00:04:28,790
Now we're going to call messages and remember we're using an underscore because you're not allowed to

60
00:04:28,790 --> 00:04:30,990
use parameter names on function types.

61
00:04:31,250 --> 00:04:35,080
So we need to use that underscore there so it doesn't have an explicit name.

62
00:04:35,210 --> 00:04:41,690
But what we can do is we can now use our model layer to return an array of message.

63
00:04:41,690 --> 00:04:42,590
Very very cool.

64
00:04:42,590 --> 00:04:47,120
So we can pass that message back to our view controller and then load it up in the function.

65
00:04:47,120 --> 00:04:51,300
Now of course to use a handler we need to basically return something.

66
00:04:51,320 --> 00:04:54,650
But in this case we're just going to return an empty function because it doesn't really matter what

67
00:04:54,650 --> 00:04:55,820
we return.

68
00:04:55,820 --> 00:05:00,170
We just need to pass these values into the functions so we can access them on the other side thanks

69
00:05:00,170 --> 00:05:01,620
to it being escaping.

70
00:05:01,640 --> 00:05:04,970
So go ahead and build and run make sure that error goes away.

71
00:05:05,150 --> 00:05:06,810
Looks like it does now.

72
00:05:06,870 --> 00:05:10,310
Let's go ahead and let's dive in to the feed.

73
00:05:10,320 --> 00:05:18,120
So call ref feed and what we're going to do is we're going to basically observe a single event when

74
00:05:18,120 --> 00:05:21,660
this gets called we're going to download every message from the feed array.

75
00:05:21,660 --> 00:05:26,880
So go ahead and call observe single event and I'll explain while we're at why we're doing single event

76
00:05:26,910 --> 00:05:28,880
instead of just observe later.

77
00:05:28,920 --> 00:05:32,490
But for now we're going to observe all the values in the feed array.

78
00:05:32,830 --> 00:05:38,580
And next we're going to actually use data snapshot here to pull down all those values so press enter

79
00:05:38,940 --> 00:05:44,120
and we're going to call this feed message snapshot and I'm actually going to copy that name.

80
00:05:44,130 --> 00:05:45,510
It's a little long.

81
00:05:45,780 --> 00:05:46,730
So that's great.

82
00:05:46,730 --> 00:05:53,310
We just pulled down our we observed everything in the feed we downloaded its value and we saved it into

83
00:05:53,310 --> 00:05:56,270
an array of data snapshot from firebase.

84
00:05:56,280 --> 00:06:02,640
Now we're going to use a guard left to create an array of data a snapshot and we're going to use guard

85
00:06:02,640 --> 00:06:05,630
let just to be safe just in case a value did not come back.

86
00:06:05,670 --> 00:06:10,770
So go ahead and type guard let feed message snapshot.

87
00:06:10,800 --> 00:06:16,860
I copied and pasted that equals feed message snapshot this one children.

88
00:06:17,040 --> 00:06:18,180
All objects.

89
00:06:18,180 --> 00:06:23,070
OK that's going to pull all of the objects out of the entire feed so if there was 100 messages we would

90
00:06:23,070 --> 00:06:24,720
get 100 objects.

91
00:06:24,720 --> 00:06:30,720
And in order to actually properly do this we need to cast it as an array of data snapshot that comes

92
00:06:30,720 --> 00:06:32,020
from firebase.

93
00:06:32,040 --> 00:06:32,460
OK.

94
00:06:32,790 --> 00:06:33,360
That's great.

95
00:06:33,360 --> 00:06:34,890
But what if this doesn't work.

96
00:06:34,890 --> 00:06:37,020
What if we don't get the objects back.

97
00:06:37,140 --> 00:06:38,580
We need to type else.

98
00:06:38,700 --> 00:06:41,530
And all we're going to do is return.

99
00:06:41,640 --> 00:06:46,110
That means we're going to like we're going to kick out of this function and we're going to not download

100
00:06:46,110 --> 00:06:49,920
any messages because there is no data so there's no need to go forward.

101
00:06:49,960 --> 00:06:50,300
Cool.

102
00:06:50,310 --> 00:06:52,700
So now we have an array of data snapshot.

103
00:06:52,710 --> 00:06:56,930
So if we had 100 messages we would have 100 elements in this data snapshot array.

104
00:06:57,030 --> 00:07:01,950
We're going to cycle through all of them and we're going to need to add them to an array of message

105
00:07:01,960 --> 00:07:04,270
because remember we're going to need to pass one back.

106
00:07:04,380 --> 00:07:06,290
Let's create one at the top.

107
00:07:06,300 --> 00:07:14,260
So go ahead and type var message array and it's going to be equal to an array of type message like.

108
00:07:14,270 --> 00:07:19,260
So what we're going to do is we're going to cycle through every data snapshot.

109
00:07:19,470 --> 00:07:22,840
We're going to pull out the content we're going to pull out the sender ID.

110
00:07:22,980 --> 00:07:27,590
We're going to create an object of message and appended to the array that was a lot of words.

111
00:07:27,600 --> 00:07:29,320
Let's do it step by step.

112
00:07:29,340 --> 00:07:37,980
So for message in feed message snapshot we're going to use a for loop to basically cycle through all

113
00:07:37,980 --> 00:07:39,100
of it.

114
00:07:39,240 --> 00:07:42,810
We're going to first create a constant to hold the content.

115
00:07:42,810 --> 00:07:43,140
OK.

116
00:07:43,170 --> 00:07:47,150
So let content equals message.

117
00:07:47,520 --> 00:07:53,150
And in order to pull out the actual value from the snapshot we need to create a child snapshot.

118
00:07:53,370 --> 00:07:54,070
OK.

119
00:07:54,270 --> 00:08:00,420
So we have a child in our messages and let's look at firebase just so we can remember what this is like

120
00:08:01,140 --> 00:08:02,540
in our message child.

121
00:08:02,540 --> 00:08:06,770
Here we have two objects we have content and Sender ID.

122
00:08:06,780 --> 00:08:10,940
Now the path right here is content that's the name of the key.

123
00:08:11,040 --> 00:08:16,320
So we're going to give it the name of the key but we don't want the key we want the value which is the

124
00:08:16,320 --> 00:08:17,820
string the message.

125
00:08:17,820 --> 00:08:19,970
So go ahead and type dot value.

126
00:08:20,070 --> 00:08:26,490
And in order to get this to work we need to cast it force cast that as a string because what comes down

127
00:08:26,490 --> 00:08:27,730
is a value of any.

128
00:08:27,750 --> 00:08:31,240
And we're going to cast that as a string so that we get it in the right data type.

129
00:08:31,260 --> 00:08:32,810
So that's our content.

130
00:08:32,820 --> 00:08:35,480
That's how you pull the content out of a data snapshot.

131
00:08:35,730 --> 00:08:40,950
Next we need to get the Sender ID so we're going to do the same thing for the sender ID so type let

132
00:08:41,520 --> 00:08:49,710
Sender ID equals message child snapshot for path and the path is Sender ID.

133
00:08:49,830 --> 00:08:52,110
Now the values what we really are interested in.

134
00:08:52,110 --> 00:08:56,940
So call value and of course as you can see its of type string.

135
00:08:56,940 --> 00:08:59,640
So we're going to do the same thing we'll call it a string.

136
00:08:59,640 --> 00:09:01,330
Very very cool.

137
00:09:01,620 --> 00:09:05,490
So now we have both content and Sender ID for every message.

138
00:09:05,520 --> 00:09:13,310
Now we're going to create a message using our message model so type let message equals message.

139
00:09:13,500 --> 00:09:18,870
Capital M and go and put a parentheses there so we can instantiate it.

140
00:09:18,870 --> 00:09:24,930
We can give it some content we can give it a Sender ID and now we have appropriately created a message

141
00:09:24,990 --> 00:09:31,000
using our content and Sender ID from firebase at the end we're going to append this message to the message

142
00:09:31,000 --> 00:09:31,730
Gerais.

143
00:09:31,990 --> 00:09:38,460
So type message or re pen and pass the message.

144
00:09:38,460 --> 00:09:41,910
Very very cool so we're going to cycle through all the messages in the snapshot.

145
00:09:42,090 --> 00:09:46,520
We're going to append it every time and by the end we'll have a nice full array of messages.

146
00:09:46,530 --> 00:09:53,960
Now of course it's saying cannot convert value of type message to argument type message and that's oh

147
00:09:54,270 --> 00:09:57,070
that's because we're trying to append the message to itself.

148
00:09:57,090 --> 00:09:57,430
Sorry.

149
00:09:57,450 --> 00:09:59,390
You just want to pass in this message.

150
00:09:59,460 --> 00:10:00,480
Awesome.

151
00:10:00,480 --> 00:10:05,660
So now once we cycle through we have a nice array full of messages at the end of the for loop.

152
00:10:05,670 --> 00:10:10,910
Go ahead and call the handler and you can see here that we need to pass it an array of messages.

153
00:10:11,040 --> 00:10:13,740
Well we have one message Gerais.

154
00:10:13,890 --> 00:10:17,120
So go ahead and call message Gerais and we're done.

155
00:10:17,130 --> 00:10:22,500
We now can download all of our messages and pass them into an array of type message.

156
00:10:22,500 --> 00:10:25,100
It's seriously so cool and so easy to do.

157
00:10:25,110 --> 00:10:29,110
So now we're going to do is we're going to go back into our view controller right.

158
00:10:29,130 --> 00:10:35,970
Our feet Visi just like here and we're going to go into our feed Visi which as I can see this is not

159
00:10:35,970 --> 00:10:41,430
actually the proper name it's the right name for the file but the class itself is not the right name.

160
00:10:41,430 --> 00:10:42,700
Let's call this feed visi.

161
00:10:42,720 --> 00:10:45,810
And you know what we're gonna have to do that with groups we see as well.

162
00:10:45,810 --> 00:10:48,180
Really glad I caught that I should have done that a long time ago.

163
00:10:48,230 --> 00:10:48,720
OK.

164
00:10:48,990 --> 00:10:49,220
Great.

165
00:10:49,220 --> 00:10:53,320
So now our class is properly declared.

166
00:10:53,490 --> 00:10:57,360
And so what we're going to do first is we're going to set up our table view so that we can actually

167
00:10:57,360 --> 00:11:01,210
download those messages and import them into our table view like we want.

168
00:11:01,260 --> 00:11:07,600
So open up mind that storyboard and open up the assistant editor and you can see here this gray box

169
00:11:07,600 --> 00:11:12,130
is a big bug it's kind of cutting off my interface builder but that's fine.

170
00:11:12,270 --> 00:11:16,990
Go to automatic go to we're in feed Visi here.

171
00:11:17,010 --> 00:11:18,890
So we're going to go to feed visi.

172
00:11:18,960 --> 00:11:24,740
Sometimes it has trouble automatically getting there so we can go there manually Lexow feed visi.

173
00:11:24,960 --> 00:11:30,780
And what we're going to do is we're going to create an IP outlet for our table view so we can call table

174
00:11:30,780 --> 00:11:36,320
view and oh interesting so it's not going to let us let's see what the deal is.

175
00:11:36,380 --> 00:11:37,940
It's of type feed.

176
00:11:38,280 --> 00:11:39,080
That's good.

177
00:11:40,090 --> 00:11:44,660
And I think just changing the name may have caused some problems let's try that again.

178
00:11:45,580 --> 00:11:46,550
Table View.

179
00:11:46,960 --> 00:11:47,220
All right.

180
00:11:47,230 --> 00:11:48,960
So I'm going to actually quit X cone.

181
00:11:49,000 --> 00:11:54,100
I'm going to go back in in just a moment and I'm going to see what the problem is here.

182
00:11:54,760 --> 00:12:04,890
Let's open it back up again and let's go ahead and try our best to connect these two feed VCs here.

183
00:12:04,900 --> 00:12:06,320
We are automatically in feed.

184
00:12:06,430 --> 00:12:07,910
OK that solved our problem.

185
00:12:08,080 --> 00:12:12,890
Now let's go ahead and create an outlet for the table view connect it.

186
00:12:13,210 --> 00:12:18,220
And now we need to set up the proper delegate methods for a table view which you've already done in

187
00:12:18,220 --> 00:12:23,200
this course so it shouldn't be a shock to you but to kind of compartmentalize the code.

188
00:12:23,200 --> 00:12:27,350
I'm actually going to create an extension of you table view and we're going to.

189
00:12:27,400 --> 00:12:32,210
Sorry an extension of feed we see and conform to both of the protocol methods I need to.

190
00:12:32,230 --> 00:12:32,710
That way.

191
00:12:32,740 --> 00:12:39,290
So go ahead and type extension feed VC UI table view.

192
00:12:39,340 --> 00:12:41,130
Can you remember your table view.

193
00:12:41,200 --> 00:12:47,120
Delegate and table view data source like so.

194
00:12:47,620 --> 00:12:51,410
Now inside here there are three that we absolutely need to conform to.

195
00:12:51,520 --> 00:12:53,270
Number of sections in table view.

196
00:12:53,380 --> 00:12:54,990
We're going to return one.

197
00:12:55,270 --> 00:12:59,490
Next is number of items or sorry number of rows in Section.

198
00:12:59,590 --> 00:13:03,970
We're going to return 4 for now just so that it doesn't yell at us or two.

199
00:13:03,970 --> 00:13:08,320
I mean for now and next is cell 4 row index path.

200
00:13:08,510 --> 00:13:09,850
K Those are required.

201
00:13:10,020 --> 00:13:12,170
And now we should be good to go.

202
00:13:12,520 --> 00:13:18,300
Let's get rid of did receive memory warning and let's get rid of that boilerplate code.

203
00:13:18,400 --> 00:13:23,170
So actually in order for this to work as you know with any table view you need to set the datasource

204
00:13:23,260 --> 00:13:24,980
and the delegate in view to load.

205
00:13:25,090 --> 00:13:27,140
So go ahead and type table view.

206
00:13:27,580 --> 00:13:33,200
Delegate equals self and we can do that now that we've properly conformed to these delegates.

207
00:13:33,220 --> 00:13:38,080
We can also call table view data source and set that to be called a self as well so it knows where it's

208
00:13:38,080 --> 00:13:40,240
getting its data from.

209
00:13:40,240 --> 00:13:46,850
So we just wrote a function get all feed messages that returns to us an array of messages.

210
00:13:46,870 --> 00:13:52,530
Now I think that we should create an array of messages here and then as soon as the view appears we're

211
00:13:52,540 --> 00:13:54,100
going to download all the messages.

212
00:13:54,140 --> 00:14:01,170
Set our local array here to be equal to messages array and then we're going to reload the table view.

213
00:14:01,190 --> 00:14:03,140
OK that's just kind of a cool way we can do it.

214
00:14:03,400 --> 00:14:05,240
So let's go ahead and create that array here.

215
00:14:05,260 --> 00:14:05,810
VAR.

216
00:14:05,830 --> 00:14:06,430
Message.

217
00:14:06,430 --> 00:14:08,020
Array.

218
00:14:08,980 --> 00:14:12,350
And it's going to be equal or to an array of message.

219
00:14:12,370 --> 00:14:15,120
And we're going to instantiate it from the get go.

220
00:14:15,140 --> 00:14:17,730
Now let's see.

221
00:14:17,750 --> 00:14:25,480
You know we have set an initial value of 2 here but it makes more sense to set it to be equal to message

222
00:14:25,800 --> 00:14:26,220
count.

223
00:14:26,230 --> 00:14:30,340
Because if we load the app there are zero messages it will show 0 messages.

224
00:14:30,340 --> 00:14:32,640
That's perfect if there are five it'll show 5.

225
00:14:32,650 --> 00:14:34,350
That way it's dynamic.

226
00:14:34,360 --> 00:14:39,820
Now what we need to do is we need to download all the messages and fill up our local array and feed

227
00:14:39,820 --> 00:14:40,630
visi.

228
00:14:40,750 --> 00:14:41,350
We're going to do that.

229
00:14:41,350 --> 00:14:46,440
In view did appear so that it happens before the view actually is finished loading.

230
00:14:46,600 --> 00:14:52,510
So we're going to call super doc view to appear and call animated.

231
00:14:52,510 --> 00:15:00,500
Now we're going to do is we're going to call our data service instance and now we can get all feed messages

232
00:15:00,670 --> 00:15:03,670
and it's going to return to us an array of feed message.

233
00:15:03,670 --> 00:15:12,540
So call this messages array and let's be more specific let's call it returned or returned messages array

234
00:15:13,420 --> 00:15:16,330
and we can set self messages array.

235
00:15:16,390 --> 00:15:23,220
So this one that we just created equals returned messages array.

236
00:15:23,300 --> 00:15:26,300
So now that they're all downloaded our array is the same.

237
00:15:26,300 --> 00:15:33,170
But in order for our table view to show the changes we should set self table view we should set it to

238
00:15:33,170 --> 00:15:37,140
reload its data so that it updates what is displayed on the table view.

239
00:15:37,160 --> 00:15:38,630
Super duper cool.

240
00:15:38,650 --> 00:15:43,580
Now we can properly download all of our messages.

241
00:15:43,670 --> 00:15:48,830
We can update our array and we can reload our table view to show the changes but we have not yet set

242
00:15:48,830 --> 00:15:50,130
up our cells.

243
00:15:50,140 --> 00:15:51,830
OK so let's do that.

244
00:15:51,860 --> 00:15:57,610
Let's go ahead and create a cell and we're going to use dequeue reusable cell with identifier.

245
00:15:57,710 --> 00:16:02,090
You've probably done this before on this course already decoying the cells so that they can be reloaded

246
00:16:02,090 --> 00:16:07,520
at will and just save a ton of memory space in the Table View and then we're going to go ahead and return

247
00:16:07,520 --> 00:16:08,510
the cell to the table view.

248
00:16:08,540 --> 00:16:11,690
So to do this we're actually going to use guard left.

249
00:16:11,720 --> 00:16:16,150
That's because it'll allow us to create a constant of our cell.

250
00:16:16,160 --> 00:16:21,860
If there is a value and if there's not then we can return an empty table to sell it's just a safe way

251
00:16:21,860 --> 00:16:22,760
to do it.

252
00:16:22,820 --> 00:16:24,670
So go ahead and type guard.

253
00:16:24,950 --> 00:16:26,040
Let sell.

254
00:16:26,120 --> 00:16:27,230
Equals.

255
00:16:27,230 --> 00:16:28,140
Table View.

256
00:16:28,340 --> 00:16:32,300
And we're going to d q a reusable cell with identifier.

257
00:16:32,470 --> 00:16:34,610
Now that identifier we have not yet set.

258
00:16:34,640 --> 00:16:36,590
And if we don't our app will crash.

259
00:16:36,590 --> 00:16:42,700
So go ahead and go into the storyboard and as soon as it loads we're going to select our cell.

260
00:16:42,980 --> 00:16:48,020
Then in the attributes inspector we need to set a reuse identifier and we're going to go ahead and type

261
00:16:49,040 --> 00:16:53,110
feed Zelle And you know what I'm actually going to copy that so that I can just paste it straight into

262
00:16:53,120 --> 00:16:57,120
feed Visi our identifier is feed cell.

263
00:16:57,380 --> 00:16:58,440
OK very cool.

264
00:16:58,640 --> 00:16:59,620
And you know what.

265
00:16:59,630 --> 00:17:05,660
In order for this to actually use our feed cell subclass we need to force or we need to optionally cast

266
00:17:05,660 --> 00:17:08,810
it as a feed cell.

267
00:17:08,810 --> 00:17:13,250
Great but what if there is no value.

268
00:17:13,250 --> 00:17:16,120
What if what if it can't do that successfully.

269
00:17:16,220 --> 00:17:18,380
Then we need to go ahead and call.

270
00:17:18,380 --> 00:17:27,750
Else and we need to return a table view cell but we can just return an empty one like so we're going

271
00:17:27,750 --> 00:17:33,060
to return you need to call return first return you table you sell.

272
00:17:33,150 --> 00:17:36,440
And now it's not going to yell at us because it has what it needs.

273
00:17:36,480 --> 00:17:41,130
Next we're going to go ahead and set up an image because if you remember in our feed cell we need an

274
00:17:41,160 --> 00:17:43,430
image an e-mail and a content.

275
00:17:43,440 --> 00:17:46,550
So we're going to go ahead and we'll set that up now.

276
00:17:46,680 --> 00:17:49,350
We're going to call Let image and we're just going to.

277
00:17:49,470 --> 00:17:53,790
For now we're not going to download or upload any images so we'll just use the default profile image

278
00:17:53,790 --> 00:18:01,770
by calling you a image named and the name is default profile image.

279
00:18:01,770 --> 00:18:02,370
OK.

280
00:18:02,760 --> 00:18:04,070
Very cool.

281
00:18:04,080 --> 00:18:06,870
We're going to go ahead and we're going to get the message.

282
00:18:06,960 --> 00:18:09,550
OK so let's say that we have our messages right.

283
00:18:10,410 --> 00:18:13,230
Message equals messages right.

284
00:18:13,890 --> 00:18:21,660
Whoopsies and we want to pull out the message that is at cell once we get the index of 0 because that

285
00:18:21,660 --> 00:18:23,040
gets the first item.

286
00:18:23,550 --> 00:18:28,200
Let's say we want the second message we get the index at 1 and that returns the second message.

287
00:18:28,200 --> 00:18:33,540
So to get all the messages we're going to just call index path dot row and this function kind of works

288
00:18:33,540 --> 00:18:34,350
like a for loop.

289
00:18:34,380 --> 00:18:36,520
It works through the entire message array.

290
00:18:36,780 --> 00:18:42,270
And for all of the items in the array it's going to basically populate them based on the row of the

291
00:18:42,270 --> 00:18:42,860
table view.

292
00:18:42,870 --> 00:18:44,190
Very cool.

293
00:18:44,190 --> 00:18:49,570
So our message has now been instantiated and now we can go ahead and configure our cell.

294
00:18:49,590 --> 00:18:54,100
So since it's a feed cell we can call cell dock configure cell.

295
00:18:54,300 --> 00:18:59,880
We can give it a profile image and you know what since we called it like this and we're calling it with

296
00:18:59,910 --> 00:19:00,960
a string name.

297
00:19:00,990 --> 00:19:03,010
We actually need to unwrap it.

298
00:19:03,030 --> 00:19:08,070
Our e-mail is going to come from message dot sender ID.

299
00:19:08,150 --> 00:19:08,690
OK.

300
00:19:08,910 --> 00:19:12,410
And our content is going to come from message content.

301
00:19:12,510 --> 00:19:18,600
Now when we're done we can return this cell to the table view and it will display after it's downloaded

302
00:19:18,600 --> 00:19:19,060
everything.

303
00:19:19,080 --> 00:19:20,300
Let's go try this out.

304
00:19:20,310 --> 00:19:21,690
Let's see how we did.

305
00:19:21,720 --> 00:19:23,490
We downloaded all of our feed messages.

306
00:19:23,490 --> 00:19:25,250
We reloaded our table view.

307
00:19:25,380 --> 00:19:31,320
We set up ourselves to go through the downloaded data and set each cell to have individual unique data.

308
00:19:31,320 --> 00:19:33,410
Let's go let's go try it out and see how we did.

309
00:19:33,420 --> 00:19:35,970
Let's see if it did what we asked.

310
00:19:35,970 --> 00:19:38,600
I hope it did and let's just give it a shot.

311
00:19:38,610 --> 00:19:39,300
Let's see.

312
00:19:39,300 --> 00:19:42,850
We should have two messages from firebase.

313
00:19:42,930 --> 00:19:44,110
Hey look at that.

314
00:19:44,370 --> 00:19:44,900
Awesome.

315
00:19:44,970 --> 00:19:47,370
Let's look at firebase we had.

316
00:19:47,580 --> 00:19:48,380
Hey what's up.

317
00:19:48,420 --> 00:19:52,290
And then this one I accidentally sent earlier and it did not have any content so we're going to need

318
00:19:52,290 --> 00:19:53,640
to fix that later on.

319
00:19:53,640 --> 00:19:55,780
But for now look it's downloading everything.

320
00:19:55,890 --> 00:19:59,280
That is the message and that is the second message that's perfect.

321
00:19:59,280 --> 00:20:01,110
Very very cool.

322
00:20:01,110 --> 00:20:02,850
So yeah it's working.

323
00:20:02,850 --> 00:20:07,320
The only issue is that we're getting the identifier the unique ID which you probably don't want to be

324
00:20:07,650 --> 00:20:08,700
public.

325
00:20:08,880 --> 00:20:14,820
Instead of getting the e-mail and we're going to set up a function in a later video that's going to

326
00:20:14,820 --> 00:20:18,900
convert the sender ID into the email from the user's account.

327
00:20:18,900 --> 00:20:22,020
Awesome job guys were downloading messages into the feed.

328
00:20:22,020 --> 00:20:25,000
And you know what let's try posting one let's see how it works when we post one.

329
00:20:25,230 --> 00:20:26,390
Hey hey hey.

330
00:20:26,790 --> 00:20:33,510
Post and we get our new post right there that is so cool.

331
00:20:33,510 --> 00:20:35,310
Amazing amazing job.

332
00:20:35,310 --> 00:20:40,680
In the next video we're going to set up a function that's going to turn these ideas into e-mails and

333
00:20:40,680 --> 00:20:46,350
we're also going to set it so that all of this content shows up at the very top of our feed the latest

334
00:20:46,350 --> 00:20:46,760
content.

335
00:20:46,760 --> 00:20:51,180
I mean at the very tippy top so amazing work let's head over to the next video and I'll see you there.
