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