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