1
00:00:07,990 --> 00:00:12,490
Hey guys this is Caleb with Dev slopes and in this video we're going to write a function that's going

2
00:00:12,490 --> 00:00:17,890
to convert our unique ID into a username or an email for our user.

3
00:00:17,890 --> 00:00:22,180
We're also going to configure the cells so that they appropriately show the username the way they're

4
00:00:22,180 --> 00:00:23,110
supposed to.

5
00:00:23,230 --> 00:00:29,110
And we're also going to change our messages array so that the feed shows in reverse.

6
00:00:29,110 --> 00:00:35,260
So the most recent post cell will show up at the very top and it's super easy to do that just to show

7
00:00:35,260 --> 00:00:38,330
you what I mean in the feed.

8
00:00:38,470 --> 00:00:42,940
The last post that I made is at the bottom we're going to set it up so that it actually goes to the

9
00:00:42,940 --> 00:00:43,320
top.

10
00:00:43,330 --> 00:00:44,200
And it's really easy.

11
00:00:44,200 --> 00:00:48,780
So let's actually start by doing that first because that's where we left off last time.

12
00:00:48,790 --> 00:00:54,710
It's literally like six letters or less or more like seven letters.

13
00:00:54,710 --> 00:01:01,370
Anyway what we need to do is the array that is returned from get all feed messages.

14
00:01:01,550 --> 00:01:05,270
We're going to actually call a function on this array.

15
00:01:05,270 --> 00:01:09,980
I actually had no idea that this was a thing and I was planning on having to write some big fancy function

16
00:01:10,280 --> 00:01:11,830
to reverse the order of the array.

17
00:01:11,840 --> 00:01:19,320
But all you lil all you need to do is literally type dot reversed.

18
00:01:19,440 --> 00:01:20,500
That's it.

19
00:01:20,520 --> 00:01:23,330
This is going to take the array and it's going to flip everything.

20
00:01:23,400 --> 00:01:26,830
And that way we can show the most recent post at the very top.

21
00:01:26,850 --> 00:01:28,830
I'm not kidding you it is that easy.

22
00:01:28,860 --> 00:01:31,890
It returns a reverse duplicate of this array.

23
00:01:31,890 --> 00:01:34,800
Let's build and run and I will show you what I mean.

24
00:01:35,010 --> 00:01:36,930
Check it out guys it's really really cool.

25
00:01:36,960 --> 00:01:43,080
It's going to give me an error because of my simulator but all you need to do is quit the sim and rerun

26
00:01:43,080 --> 00:01:43,800
it.

27
00:01:43,800 --> 00:01:51,420
It will reopen the simulator and as soon as it's ready we will be able to see how easy it is to reverse

28
00:01:51,480 --> 00:01:53,130
all of our messages.

29
00:01:53,340 --> 00:01:56,850
By the way while this is loading I'm going to open the data service because we're going to be adding

30
00:01:56,850 --> 00:02:00,330
a function in there in just a moment but now it's ready.

31
00:02:00,330 --> 00:02:03,250
So it downloads all the messages and do you see that they're in reverse order.

32
00:02:03,250 --> 00:02:05,330
Now watch what happens when I post.

33
00:02:05,520 --> 00:02:09,040
This is the newest post.

34
00:02:09,270 --> 00:02:14,850
And you know it just for fun let's add an emoji nice thing.

35
00:02:14,860 --> 00:02:16,220
OK thing.

36
00:02:16,360 --> 00:02:23,060
And send and it shows up at the very top that is how easy it is to reverse all of our posts.

37
00:02:23,060 --> 00:02:23,840
So awesome.

38
00:02:23,850 --> 00:02:24,890
That's easy.

39
00:02:24,890 --> 00:02:31,100
Now we're going to write a function to convert our you ID into a username so to do that we're going

40
00:02:31,100 --> 00:02:38,080
to go into the data service and we're going to write a function called phunk get username for you ID.

41
00:02:39,140 --> 00:02:42,020
OK and I'm using an internal parameter there.

42
00:02:42,020 --> 00:02:48,920
And the thing is we're going to be using some firebase closures and so to get values out we need to

43
00:02:48,920 --> 00:02:50,840
use a completion handler.

44
00:02:50,840 --> 00:02:54,960
So go ahead and type handler at escaping like we have been.

45
00:02:55,130 --> 00:03:00,410
You should be an expert at this by now and in the function we're going to go ahead and pass a value

46
00:03:00,410 --> 00:03:03,450
called username of type string.

47
00:03:03,800 --> 00:03:04,850
All right.

48
00:03:04,850 --> 00:03:08,090
We're going to use that at the very end once we have our user name.

49
00:03:08,120 --> 00:03:13,430
Now we need to do is we need to observe the users reference and we need to cycle through all the users

50
00:03:13,460 --> 00:03:17,210
and find one that matches the ID we pass in.

51
00:03:17,210 --> 00:03:23,180
So to do that go ahead and call ref users observe single event.

52
00:03:23,180 --> 00:03:26,870
The reason we're doing that is because we only needed to look through at one time we don't need it to

53
00:03:26,870 --> 00:03:28,670
persistently observe.

54
00:03:28,670 --> 00:03:32,820
We're going to go ahead and observe value meaning all values in the user's reference.

55
00:03:33,050 --> 00:03:35,210
And we're going to get a snapshot back.

56
00:03:35,270 --> 00:03:37,630
And this is going to be called user snapshot.

57
00:03:37,640 --> 00:03:39,440
That's just what I'm naming it.

58
00:03:39,440 --> 00:03:45,050
Now what we're going to do is we're going to create a constant that holds this snapshot then we're going

59
00:03:45,050 --> 00:03:47,720
to write a for loop to cycle through all of them.

60
00:03:47,750 --> 00:03:55,730
So go ahead and type guard let users snapshot equals the user snapshot that we got returned snapshot

61
00:03:56,230 --> 00:04:00,020
dot children meaning all the children inside of the user snapshot.

62
00:04:00,020 --> 00:04:03,390
And we're going to return all of the objects we need to force.

63
00:04:03,400 --> 00:04:09,210
Can this just like before as a an array of WIPs data snapshot.

64
00:04:09,530 --> 00:04:13,960
Now the only thing is if we get nothing back we should do something and that is to call.

65
00:04:13,970 --> 00:04:17,440
Else wups else.

66
00:04:17,630 --> 00:04:23,070
And then inside of here we can just return and get out of this function.

67
00:04:23,090 --> 00:04:26,300
So that's what we're going to do if there is nothing return we'll just get out so that we don't have

68
00:04:26,300 --> 00:04:32,500
a crash now that we have a user snapshot assuming we get some users downloaded.

69
00:04:32,510 --> 00:04:40,280
We're going to go ahead and call for user and user snapshot and we're going to basically check to see

70
00:04:40,670 --> 00:04:48,830
if a certain user dot key because remember if we look at firebase Let's pull it up every user.

71
00:04:49,000 --> 00:04:52,270
Oh oh that's not good.

72
00:04:52,460 --> 00:04:59,030
So it looks like we've authenticated some users but the user it was deleted but it's still remaining

73
00:04:59,090 --> 00:05:01,160
inside of firebase.

74
00:05:01,390 --> 00:05:05,120
OK let's finish this function up and then we'll go fix it so that we can actually sign out and then

75
00:05:05,120 --> 00:05:09,220
sign in as a new user because right now we have no users in our Snapshot.

76
00:05:09,470 --> 00:05:20,090
If user Docky is equal to the ID we pass in k we can think about it like the feed has users and the

77
00:05:20,090 --> 00:05:21,570
users have a unique ID.

78
00:05:21,920 --> 00:05:31,010
If the the key here matches the user id we pass in then we can call handler dot or wups handler and

79
00:05:31,010 --> 00:05:32,810
we're going to pass it a string.

80
00:05:33,050 --> 00:05:39,240
But in order to get that we can go into the user account and we can call child snapshot for path.

81
00:05:39,320 --> 00:05:50,480
If you remember when we create a user Let's go to log in Visi we pass in the where is it we pass in

82
00:05:50,570 --> 00:05:52,410
an e-mail.

83
00:05:52,560 --> 00:05:54,600
You know what it might be and register user Let's see.

84
00:05:54,620 --> 00:05:55,280
Yes.

85
00:05:55,280 --> 00:05:55,460
Yes.

86
00:05:55,460 --> 00:06:03,680
We pass in a child called e-mail and so let's go ahead and let's go for the child called e-mail.

87
00:06:03,680 --> 00:06:09,320
Now of course we want the value not the key and we want to cast it as a string because we need to pass

88
00:06:09,320 --> 00:06:11,380
back a string to our handler.

89
00:06:11,430 --> 00:06:14,890
Now when we pass a I.D. it'll cycle through here.

90
00:06:14,950 --> 00:06:21,620
It will find the user that matches that you I.D. and then we will get the e-mail back for them.

91
00:06:21,620 --> 00:06:25,530
So in order to actually utilize this we need to go to the feed.

92
00:06:25,820 --> 00:06:31,610
And what we're going to do is we're actually going to use the sender ID but we're going to pass it into

93
00:06:31,610 --> 00:06:33,560
our get username function first.

94
00:06:33,560 --> 00:06:40,250
So let's go ahead and call data service instance get username for you I.D..

95
00:06:40,550 --> 00:06:42,290
We have that right here.

96
00:06:42,290 --> 00:06:48,500
Right message dot sender ID so let's pass that in to our function and the handlers where we get our

97
00:06:48,500 --> 00:06:49,370
username back.

98
00:06:49,370 --> 00:06:56,990
So let's call returned username and we can call configure cell in here now.

99
00:06:56,990 --> 00:07:02,140
So we're going to configure the cell with the proper username as returned username.

100
00:07:02,560 --> 00:07:02,940
OK.

101
00:07:02,960 --> 00:07:06,150
And that will give us our e-mail value to show up in our cell.

102
00:07:06,160 --> 00:07:09,310
Super duper cool but we're going to run into an issue.

103
00:07:09,320 --> 00:07:13,880
Let's build and run the app and we'll see that we'll get nothing back for the username.

104
00:07:13,870 --> 00:07:17,570
We may even have a crash because we currently have no users in our account.

105
00:07:18,320 --> 00:07:20,780
We're just going to get our default message back.

106
00:07:20,780 --> 00:07:26,780
We have the right number but we can't configure the cell because we're not actually getting a value

107
00:07:26,780 --> 00:07:28,760
back and that is a problem.

108
00:07:28,760 --> 00:07:33,930
So we need to actually go ahead and set up MVH see to sign us out properly.

109
00:07:33,950 --> 00:07:40,310
So let's go ahead and let's do that now by going to the story board and we're going to open up the assistant

110
00:07:40,310 --> 00:07:42,770
editor as soon as it's done loading.

111
00:07:42,830 --> 00:07:43,440
There we go.

112
00:07:44,920 --> 00:07:53,350
And let's go ahead and let's pull open MVH see which is right here and we're going to update our action

113
00:07:53,350 --> 00:07:58,630
to actually contain the proper sign out code and what we're going to do is we're going to set up what's

114
00:07:58,630 --> 00:08:00,920
called a UI alert controller.

115
00:08:01,000 --> 00:08:02,650
But we're going to modify it for log out.

116
00:08:02,650 --> 00:08:03,460
It's very cool.

117
00:08:03,460 --> 00:08:12,040
So let's go ahead and let's create an instance of you Isler controller let's call it let maybe log out

118
00:08:12,070 --> 00:08:17,130
pop up and it's going to be equal to UI alerts controller.

119
00:08:17,140 --> 00:08:20,840
Now of course this is going to have a title and a message.

120
00:08:21,010 --> 00:08:23,420
The title is just going to be log out.

121
00:08:23,480 --> 00:08:32,990
The question mark the message will be are you sure you want to log out and the preferred style.

122
00:08:33,010 --> 00:08:38,210
This is where we're going to get the log out style pop up as we're going to call action sheet.

123
00:08:38,490 --> 00:08:39,000
OK.

124
00:08:39,130 --> 00:08:43,450
That's going to pop up from the bottom similar to like when you share stuff if you wanted to share something

125
00:08:43,480 --> 00:08:46,430
and it pops up that list of options of where you can share it.

126
00:08:46,450 --> 00:08:48,060
That's an action sheet.

127
00:08:48,070 --> 00:08:51,850
Next we're going to have to create a log out action for when we tap on the button.

128
00:08:51,850 --> 00:08:52,870
What's it going to do.

129
00:08:53,110 --> 00:08:54,600
So let's do that now by typing.

130
00:08:54,640 --> 00:08:58,750
Let pop or let's do let log out.

131
00:08:58,750 --> 00:09:00,000
Log out.

132
00:09:00,040 --> 00:09:03,110
Action equal UI alert.

133
00:09:03,190 --> 00:09:04,160
Action.

134
00:09:04,510 --> 00:09:07,720
And it kind of has a similar similar style here.

135
00:09:07,720 --> 00:09:15,040
We're going to give it a title of log out a style of destructive and that means if you look it says

136
00:09:15,520 --> 00:09:20,530
well it doesn't tell you here but it basically means that it's used for things that are destructive

137
00:09:20,530 --> 00:09:25,450
like we're destroying the user's account where we're removing it completely from our app.

138
00:09:25,450 --> 00:09:33,310
So what's going to happen is when the button is tapped we're going to try to sign out and we can use

139
00:09:33,370 --> 00:09:35,520
some fire based stuff for that.

140
00:09:35,530 --> 00:09:39,760
I'm actually going to pull open MVH see in full screen here so you can see it really good.

141
00:09:39,760 --> 00:09:40,580
There we go.

142
00:09:40,840 --> 00:09:45,610
And so inside of this completion handler after the button is tapped we're going to go ahead and we're

143
00:09:45,610 --> 00:09:53,110
going to call off ah with whoops we have not imported firebase import firebase.

144
00:09:53,110 --> 00:09:54,050
There we go.

145
00:09:54,310 --> 00:09:56,760
And we're going to call off Auth..

146
00:09:57,070 --> 00:09:58,350
Sign out.

147
00:09:58,480 --> 00:10:02,080
And did you see right there it says sign out and says that it throws.

148
00:10:02,080 --> 00:10:03,940
That means it throws errors.

149
00:10:03,940 --> 00:10:07,560
And because of that we need to use do try ok.

150
00:10:07,600 --> 00:10:11,770
That's a safe way for us to call things that could have critical errors.

151
00:10:11,770 --> 00:10:14,010
So to do this we're going to do.

152
00:10:14,410 --> 00:10:18,460
And then at the end we're going to call catch and that's where errors are handled.

153
00:10:18,460 --> 00:10:25,090
So cut this and move it into the do block and now we need to call try because that tells us that we're

154
00:10:25,090 --> 00:10:31,390
going to try to sign out and assuming that works we should instantiate our log in Visi once we log out

155
00:10:31,390 --> 00:10:34,500
it should pop up the log and visi again so that we can see it.

156
00:10:34,510 --> 00:10:44,920
So go ahead and type let log in VC equal storyboard instantiate view controller with identifier and

157
00:10:44,920 --> 00:10:48,500
we're going to call our identifier which is off the seat.

158
00:10:48,800 --> 00:10:49,090
OK.

159
00:10:49,090 --> 00:10:56,980
Now in order for this to actually show up as an author Visi we need to cast it as author Visi just like

160
00:10:56,980 --> 00:10:57,910
that.

161
00:10:58,210 --> 00:11:03,060
And now we can actually present it on top of whatever view controller we're on which happens to be MVH

162
00:11:03,070 --> 00:11:03,640
seat.

163
00:11:03,670 --> 00:11:11,800
So go ahead and type self up present and we're going to present log and visi just like that animated

164
00:11:11,800 --> 00:11:17,230
of course and we don't care about what happens at the end because it doesn't really matter.

165
00:11:17,230 --> 00:11:19,320
We've signed out and that's great.

166
00:11:19,690 --> 00:11:20,220
OK.

167
00:11:20,380 --> 00:11:25,930
Since the storyboard here is optional we need to force on RRAP log in VC but it's cool.

168
00:11:26,230 --> 00:11:30,520
Oh you know what I just realized it's obviously not log in B C we should use the right name.

169
00:11:30,520 --> 00:11:31,860
Sorry about that.

170
00:11:31,870 --> 00:11:36,100
So change this to Auth. Visi and there we go.

171
00:11:36,100 --> 00:11:41,620
Now we are successfully presenting a view controller but if we can't then we're just going to print

172
00:11:42,160 --> 00:11:45,530
the error and you're probably wondering where did the error come from.

173
00:11:45,550 --> 00:11:47,470
It comes from Sign out.

174
00:11:47,470 --> 00:11:53,980
But since we're using a do catch block it automatically captures in a variable called error and sign

175
00:11:53,980 --> 00:12:00,520
out passes any values to this so if there's a problem we'll know next what we need to do now that our

176
00:12:00,520 --> 00:12:04,480
action is done is we need to add the action to our log out pop up.

177
00:12:04,480 --> 00:12:06,400
So we need to go ahead and blow this.

178
00:12:06,400 --> 00:12:13,640
Now that our log out action is finished call log out pop up add action and give it the log out action.

179
00:12:13,840 --> 00:12:15,370
OK that's simple.

180
00:12:15,370 --> 00:12:20,020
Now when the pop up goes up it knows what it can do and we push the log out button.

181
00:12:20,050 --> 00:12:24,280
And finally when we push the sign out button we need to present this whole alert.

182
00:12:24,280 --> 00:12:28,960
So now we can call present and we're going to call log out pop up.

183
00:12:28,960 --> 00:12:30,690
That's the alert controller.

184
00:12:30,730 --> 00:12:32,420
Of course we want it to be animated.

185
00:12:32,430 --> 00:12:38,930
But we do not care whether it completes or not because we handle that in here with our DO catch block.

186
00:12:39,070 --> 00:12:44,290
Let's go ahead and let's try this let's try to remove our account and then we're going to go ahead and

187
00:12:44,900 --> 00:12:51,270
move on to where we were before OK here we go and we get billed failed.

188
00:12:51,290 --> 00:12:53,210
Interesting Let's see what the problem is.

189
00:12:53,240 --> 00:12:55,080
Oh implicit use of self enclosure.

190
00:12:55,100 --> 00:12:57,260
We need to use self to access the storyboard.

191
00:12:57,350 --> 00:12:58,820
That makes sense.

192
00:12:58,830 --> 00:13:04,700
Can you go ahead and build and run and let's pull open the simulator here so we can see how that works

193
00:13:04,700 --> 00:13:06,250
when we log out.

194
00:13:06,470 --> 00:13:12,410
If successful the log out or the authentication VC should pop up automatically which would be awesome.

195
00:13:12,410 --> 00:13:14,100
So let's go give it a shot.

196
00:13:14,120 --> 00:13:16,190
Let's try to log out.

197
00:13:16,190 --> 00:13:18,320
There's our pop up and there's our message.

198
00:13:18,320 --> 00:13:21,860
Let's go ahead and tap log out and our log in Visi shows up.

199
00:13:21,860 --> 00:13:22,560
That's amazing.

200
00:13:22,580 --> 00:13:23,630
OK perfect.

201
00:13:23,630 --> 00:13:26,580
Let's log back and I'm going to actually create a new account here.

202
00:13:26,610 --> 00:13:29,500
How about Harvey Dent.

203
00:13:29,680 --> 00:13:32,880
Hey password of course is Batman.

204
00:13:32,930 --> 00:13:33,910
Let's sign in.

205
00:13:36,480 --> 00:13:37,830
All right there we go.

206
00:13:38,310 --> 00:13:38,970
Oh and you know what.

207
00:13:38,970 --> 00:13:39,450
Look at that.

208
00:13:39,460 --> 00:13:43,310
We get stuck on our off the sea we need to go fix that.

209
00:13:43,350 --> 00:13:45,720
And I know exactly how to do it.

210
00:13:45,850 --> 00:13:53,700
Of AVC when the view appears we should set it to if we are logged in we should set the view to dismiss.

211
00:13:53,700 --> 00:13:58,110
So let's go ahead and call you did appear because that's called every time the view appears not just

212
00:13:58,110 --> 00:13:59,890
when it loads for the first time.

213
00:13:59,970 --> 00:14:07,070
Call superdog viewed it appear and pass in a boolean of animated so that it's nice and animated.

214
00:14:07,170 --> 00:14:15,420
And now we need to do is we need to check using firebase first import firebase and we're going to basically

215
00:14:15,420 --> 00:14:18,090
check if off off.

216
00:14:18,150 --> 00:14:28,680
Current User is not nil wups is not nil meaning if there's a user go ahead and dismiss the view controller

217
00:14:30,150 --> 00:14:34,770
because think about it if you're logged out and this pops up there's no user once you're logged in it

218
00:14:34,770 --> 00:14:36,780
should automatically dismiss.

219
00:14:36,780 --> 00:14:37,130
OK.

220
00:14:37,230 --> 00:14:38,460
So let's go try that again.

221
00:14:38,460 --> 00:14:41,930
We're going to build and run pop this thing up and we'll go see if it worked.

222
00:14:44,420 --> 00:14:44,740
OK.

223
00:14:44,820 --> 00:14:47,300
So we're going to log out log out.

224
00:14:47,340 --> 00:14:48,420
It pops up.

225
00:14:48,420 --> 00:14:53,280
Let's log into my account here Harvey at dent dot com.

226
00:14:53,330 --> 00:15:00,870
That man is my password and let's sign in and let's see if it disappears.

227
00:15:01,160 --> 00:15:03,060
Oh you know I guess I got my password wrong.

228
00:15:03,110 --> 00:15:03,830
Bat Man.

229
00:15:03,830 --> 00:15:04,560
There we go.

230
00:15:04,600 --> 00:15:05,620
Seinen.

231
00:15:06,470 --> 00:15:08,090
And it dismisses the way we would hope.

232
00:15:08,090 --> 00:15:08,900
That's beautiful.

233
00:15:08,900 --> 00:15:09,420
OK.

234
00:15:09,680 --> 00:15:10,150
Awesome.

235
00:15:10,190 --> 00:15:16,760
We're still having the issue of our fields here not showing up and let's go figure out why that is.

236
00:15:17,020 --> 00:15:17,440
OK.

237
00:15:17,570 --> 00:15:18,290
Let's see.

238
00:15:18,500 --> 00:15:22,340
We have a user he has an e-mail and the provider is firebase.

239
00:15:22,340 --> 00:15:29,450
So let's go look at Pheed VC and let's figure out what the problem is.

240
00:15:29,540 --> 00:15:34,770
Now get user name passes in the sender ID and we get a user name return.

241
00:15:34,790 --> 00:15:40,060
But if you think about it all of these messages were not sent by a user in our database.

242
00:15:40,070 --> 00:15:43,970
So we actually should get rid of all these messages because they're never going to show up.

243
00:15:43,970 --> 00:15:45,260
From a user.

244
00:15:45,350 --> 00:15:50,820
Now what we should do and you see they disappear which is cool because it's real time.

245
00:15:51,010 --> 00:15:55,400
Let's go ahead and let's add a user or out a message from Harvey Dent.

246
00:15:55,510 --> 00:15:56,680
Hey Batman.

247
00:15:56,680 --> 00:15:58,630
You stink.

248
00:15:58,630 --> 00:16:02,310
I heard Robin laid an egg.

249
00:16:03,130 --> 00:16:04,680
Lol ok.

250
00:16:04,810 --> 00:16:06,300
Let's send it.

251
00:16:06,460 --> 00:16:09,110
And it shows up as Harvey Dent dotcom.

252
00:16:09,120 --> 00:16:13,240
That's exactly what it's supposed to do it's supposed to get all the usernames and it's supposed to

253
00:16:13,240 --> 00:16:15,720
post them at the top there of the cell.

254
00:16:15,880 --> 00:16:17,410
So so cool.

255
00:16:17,500 --> 00:16:18,520
That's working.

256
00:16:18,520 --> 00:16:22,600
I did notice something while we were doing this and this is just part of building apps you notice things

257
00:16:22,600 --> 00:16:23,510
here and there.

258
00:16:23,830 --> 00:16:30,820
When we pull open post post a new or create post-PC user at breakpoint is still showing up.

259
00:16:30,820 --> 00:16:34,640
Not the current users not the current users name.

260
00:16:34,690 --> 00:16:35,830
Let's fix that.

261
00:16:35,890 --> 00:16:43,570
All we need to do is to go into create post-PC and we need to create an IP outlet for the users e-mail

262
00:16:43,570 --> 00:16:47,330
label and we've already done it and it's already set up it's ready to go.

263
00:16:47,500 --> 00:16:52,050
But we have just not yet set it up to pass in the e-mail for the user.

264
00:16:52,050 --> 00:16:52,540
OK.

265
00:16:52,900 --> 00:16:58,720
So what we're going to do to do that is basically to call view will appear because that's going to get

266
00:16:58,720 --> 00:17:04,270
called before the view loads and it'll update the view changes so that it doesn't show the wrong email

267
00:17:04,270 --> 00:17:07,510
first and then quickly flash to change to show the right one.

268
00:17:07,660 --> 00:17:09,090
It'll just show the right one from the get go.

269
00:17:09,090 --> 00:17:11,840
So-called super You will appear animated.

270
00:17:12,100 --> 00:17:17,620
And what we're going to do since we're already logged in we can just pull out the information from firebase

271
00:17:17,650 --> 00:17:19,770
and just get the email straight from the current user.

272
00:17:19,840 --> 00:17:27,270
So call self e-mail label dot text and set it to off off off.

273
00:17:27,400 --> 00:17:32,830
Current User and it has an email property we can just pull out the user's e-mail address straight from

274
00:17:32,830 --> 00:17:33,780
firebase.

275
00:17:33,790 --> 00:17:35,310
So go ahead and build and run.

276
00:17:35,360 --> 00:17:38,620
And let's go see if this change is reflected appropriately.

277
00:17:43,170 --> 00:17:46,410
And the reason I'm doing this is because you can't even get to this screen unless you're logged in.

278
00:17:46,410 --> 00:17:50,220
So go ahead and open it and look at that Harvey at dent dot com.

279
00:17:50,220 --> 00:17:52,580
There's one other place we should do this.

280
00:17:52,590 --> 00:17:54,270
It's here in visi.

281
00:17:54,480 --> 00:17:59,310
So I'm actually going to just copy this and go to TVC and I'm going to paste it because we said the

282
00:17:59,310 --> 00:18:01,360
same name for the e-mail label.

283
00:18:01,440 --> 00:18:05,640
Let's build and run again and let's make sure that it works OK.

284
00:18:09,750 --> 00:18:10,940
OK let's check it out.

285
00:18:10,940 --> 00:18:11,390
All right.

286
00:18:11,420 --> 00:18:11,980
Very good.

287
00:18:11,990 --> 00:18:17,840
But what happens if we log out let's try logging out and log into a new account.

288
00:18:17,840 --> 00:18:19,340
Let me log into my old account.

289
00:18:19,370 --> 00:18:29,120
Well I mean log into a new one here maybe Batman at Gotham dot net and the password Joker sucks.

290
00:18:29,960 --> 00:18:34,370
Seinen.

291
00:18:34,730 --> 00:18:39,390
And here's the problem it's still holding the old user's name.

292
00:18:39,620 --> 00:18:45,980
Now a way that we can fix this is if we put it in view will appear because every time the view appears

293
00:18:45,980 --> 00:18:47,620
it's going to change the current user.

294
00:18:47,620 --> 00:18:50,370
So let's call you appear super dog.

295
00:18:50,390 --> 00:18:52,740
You will appear animated.

296
00:18:53,000 --> 00:18:56,370
And we will update this as soon as the view appears that way.

297
00:18:56,450 --> 00:18:57,610
We don't have that same issue.

298
00:18:57,620 --> 00:19:02,870
So go ahead and build and run it let it happen and as soon as it goes up we will check to see if it

299
00:19:02,870 --> 00:19:04,000
worked.

300
00:19:05,010 --> 00:19:05,750
Here we go.

301
00:19:06,090 --> 00:19:06,290
OK.

302
00:19:06,300 --> 00:19:07,820
So Batman at Gotham dot net.

303
00:19:07,970 --> 00:19:09,610
It's actually make a post.

304
00:19:09,980 --> 00:19:13,550
Hey there it is up at the top.

305
00:19:13,550 --> 00:19:14,710
Very nice.

306
00:19:14,720 --> 00:19:22,610
Now when we log out and log back in let's log in is Harvey Dent dotcom.

307
00:19:22,990 --> 00:19:24,320
What was my password.

308
00:19:24,330 --> 00:19:25,610
Batman I think.

309
00:19:25,920 --> 00:19:31,320
Let's sign in and it should update the user and show the new user name as soon as the view appears very

310
00:19:31,410 --> 00:19:32,670
very awesome.

311
00:19:32,670 --> 00:19:36,990
So let's go ahead let's move on to the next video we did just a couple of little tweaks here just for

312
00:19:36,990 --> 00:19:37,640
fun.

313
00:19:37,740 --> 00:19:38,650
In the middle of it.

314
00:19:38,730 --> 00:19:44,190
But now our feed cells are showing usernames our message array is reversed so the most current post

315
00:19:44,190 --> 00:19:45,380
is on top.

316
00:19:45,400 --> 00:19:50,640
And guys this is looking really good so far in the next video we're going to create one of my favorite

317
00:19:50,820 --> 00:19:56,250
controllers in this whole app it's called create group Visi and it's going to allow us to search through

318
00:19:56,310 --> 00:20:01,140
all the users that have created accounts in our apps and add them specifically it's going to be really

319
00:20:01,140 --> 00:20:01,870
really cool.

320
00:20:02,010 --> 00:20:05,260
So let's move on to the next video and let's start adding some groups into our app.
