0
1
00:00:00,350 --> 00:00:00,680
All right.
1

2
00:00:00,750 --> 00:00:07,140
So first things first, you should have cloned the starting project from the GitHub repository FlashChat
2

3
00:00:07,150 --> 00:00:14,700
iOS 13, and we're going to clone it like you have done before many, many times.
3

4
00:00:15,010 --> 00:00:19,180
So once you've cloned it, you should end up with a file that looks like this.
4

5
00:00:19,300 --> 00:00:25,540
And if you go ahead and expand the folders, then you'll see that we've got a Main.storyboard that's already
5

6
00:00:25,540 --> 00:00:26,700
been set up.
6

7
00:00:26,950 --> 00:00:30,420
And in this app, we've got a little bit more of a complex setup.
7

8
00:00:30,430 --> 00:00:35,620
We've got four screens and this first screen is the welcome screen,
8

9
00:00:35,680 --> 00:00:39,280
then we've got a registration screen, a login screen,
9

10
00:00:39,280 --> 00:00:41,830
and finally, the actual chat screen.
10

11
00:00:42,460 --> 00:00:45,990
So notice how we're using a lot of custom assets in here.
11

12
00:00:46,000 --> 00:00:52,600
For example, the way that we're able to get these shadows and shapes around these text fields, the email
12

13
00:00:52,600 --> 00:00:58,370
and password text fields is by using some custom assets that we've added in here.
13

14
00:00:58,390 --> 00:01:06,130
So these have their custom shadows and shapes and we've basically just used these as an Image view, so
14

15
00:01:06,130 --> 00:01:11,730
that we can give our app some custom design and make it look beautiful.
15

16
00:01:11,820 --> 00:01:18,240
Now, in addition, we've got some colors that are going to be the brand colors for our app.
16

17
00:01:18,240 --> 00:01:24,480
So we've defined these colors over here. And then we've given them a name so that we'll be able to identify
17

18
00:01:24,480 --> 00:01:26,030
it in our app.
18

19
00:01:26,160 --> 00:01:32,400
And we've also got some other images, such as the app icons and the avatars that we'll be using in the
19

20
00:01:32,400 --> 00:01:33,330
app.
20

21
00:01:33,330 --> 00:01:40,320
So heading back over to the Main.storyboard, you'll notice that if you go into Assistant mode that
21

22
00:01:40,320 --> 00:01:44,700
we've already linked up some of these IBOutlets and IBActions.
22

23
00:01:44,700 --> 00:01:50,550
So for example, over here on the welcome screen, we've got the titleLabel that's been linked up, and then
23

24
00:01:50,580 --> 00:01:56,880
over here on the registration and login screens, we've got these text fields already linked up and the
24

25
00:01:56,880 --> 00:01:58,770
IBActions for the buttons.
25

26
00:01:58,770 --> 00:02:05,340
Now, if you don't see the files that are associated with these design files automatically showing up
26

27
00:02:05,400 --> 00:02:13,030
when you go to the assistant view, then it might just be that you have to click on automatic and select
27

28
00:02:13,030 --> 00:02:18,230
it manually which is a little bit ironic given that it's called automatic.
28

29
00:02:18,320 --> 00:02:24,710
But essentially, the reason why these are paired up if you remember is because we've actually linked
29

30
00:02:24,710 --> 00:02:31,040
it in the storyboard file, so when we've selected each of these screens and we've created these new view
30

31
00:02:31,040 --> 00:02:38,530
controllers, we've added it inside here as the custom class that's going to control the screen.
31

32
00:02:38,540 --> 00:02:43,120
And we've done that for each of these screens, so ChatViewController is linked
32

33
00:02:43,130 --> 00:02:48,980
to ChatViewController.swift, the login view controller screen is linked to the LoginViewController.swift,
33

34
00:02:48,980 --> 00:02:56,180
et cetera. But sometimes Xcode is a little bit weird and it shows you this file which is actually
34

35
00:02:56,240 --> 00:03:01,820
the header file, which is not what we want, and instead you want to click on Automatic and select the
35

36
00:03:01,820 --> 00:03:03,410
Swift File like this.
36

37
00:03:03,410 --> 00:03:09,500
So let's go ahead and close down our assistant and let's head back to our Main.storyboard.
37

38
00:03:09,620 --> 00:03:15,410
So notice that most of the components that have been added here are things that you've already seen
38

39
00:03:15,410 --> 00:03:15,770
before,
39

40
00:03:15,770 --> 00:03:22,940
so labels, buttons, text views, image views, but this we've yet to use.
40

41
00:03:23,120 --> 00:03:29,930
So this is what's called a table view and you can get hold of it by simply going to the Object library
41

42
00:03:30,410 --> 00:03:35,570
and searching for a table view. And you can read through this,
42

43
00:03:35,630 --> 00:03:40,840
but basically, it's just a way for us to be able to display data in a list.
43

44
00:03:41,000 --> 00:03:46,490
So on Android, it's called a list view and it's probably a little bit better of a description,
44

45
00:03:46,490 --> 00:03:47,570
rather than table view.
45

46
00:03:47,570 --> 00:03:50,770
But if you have an iPhone, then you've already seen table views.
46

47
00:03:50,840 --> 00:03:56,900
If you think about your mail app, this is a bog-standard table view without any modifications.
47

48
00:03:57,110 --> 00:04:04,160
And even if you think about the chat app, this is actually still based on a table view because it's vertically
48

49
00:04:04,160 --> 00:04:13,070
stacked cells and each of these are just simply customized to look a little bit more pretty than the
49

50
00:04:13,070 --> 00:04:19,220
standard table view, and we're gonna be doing this later on ourselves, as well creating these custom views
50

51
00:04:19,550 --> 00:04:26,100
in our messaging app. So if in the future, you need a table view or you need the functionality of this
51

52
00:04:26,100 --> 00:04:32,790
kind of vertically scrolling and stacked components, you'll know to get it from the object library. 
52

53
00:04:32,790 --> 00:04:40,560
Drag it on and link it up as an outlet as you would for any other component on the Main.storyboard.
53

54
00:04:40,560 --> 00:04:45,330
So the other thing that you might have noticed when you've opened up this app is that we've got a couple
54

55
00:04:45,330 --> 00:04:52,350
of warnings here. And they're telling us that there's a couple of view controllers on our Main.toryboard
55

56
00:04:52,710 --> 00:04:56,450
which is unreachable because it has no entry points.
56

57
00:04:56,820 --> 00:04:57,780
So what does that mean?
57

58
00:04:57,780 --> 00:05:04,230
Well, notice how we've got these four screens. We've got this arrow which determines where the app is
58

59
00:05:04,230 --> 00:05:07,320
going to start out which screen it's going to show first.
59

60
00:05:07,320 --> 00:05:13,440
And you can drag this around or you can simply select the View Controller and click Is Initial View
60

61
00:05:13,440 --> 00:05:14,310
Controller.
61

62
00:05:14,340 --> 00:05:16,010
It does exactly the same thing.
62

63
00:05:16,050 --> 00:05:21,660
I find it easier to just visually just drag that arrow around. But you can see that if this is the entry
63

64
00:05:21,660 --> 00:05:24,750
point, this is the first screen that the user sees.
64

65
00:05:24,750 --> 00:05:30,490
Then in order to get to some of these other screens, we're going to need some segue ways, right?
65

66
00:05:30,510 --> 00:05:34,780
And at the moment, there are no segues because I've left it for you to set up.
66

67
00:05:35,340 --> 00:05:41,250
So I want you to see if you remember how to set up segues and I want you to set up a segue between
67

68
00:05:41,250 --> 00:05:44,040
the RegisterViewController and the ChatViewController,
68

69
00:05:44,340 --> 00:05:50,100
so from this screen to this screen. And then another one between the LoginViewController and the
69

70
00:05:50,110 --> 00:05:50,880
ChatViewController,
70

71
00:05:51,240 --> 00:05:57,730
so from the screen to the screen. Because remember, once the user successfully registers all logs in which
71

72
00:05:57,750 --> 00:06:00,990
take them directly to the ChatViewController.
72

73
00:06:01,650 --> 00:06:09,080
So pause the video and see if you can complete that challenge.
73

74
00:06:09,420 --> 00:06:09,750
All right.
74

75
00:06:09,780 --> 00:06:12,590
So this shouldn't be too hard. 
75

76
00:06:12,660 --> 00:06:19,350
Remember, firstly, we have to select the entire view controller, and you can either click and drag like this, or
76

77
00:06:19,350 --> 00:06:26,900
the easiest way is actually just to click on this little yellow icon up here which does the same thing.
77

78
00:06:26,910 --> 00:06:32,820
So, now from this point, from the RegisterViewController, we're going to make a link or a segue to the
78

79
00:06:32,820 --> 00:06:34,140
CharViewController.
79

80
00:06:34,440 --> 00:06:40,170
So I'm going to hold down the control key on my keyboard, click from here and drag it over to this screen,
80

81
00:06:40,650 --> 00:06:42,310
and then go ahead and let go.
81

82
00:06:42,360 --> 00:06:48,600
And now I've created a segue and I'm going to choose a bog standard show segue as we have done many,
82

83
00:06:48,600 --> 00:06:50,230
many times before.
83

84
00:06:50,490 --> 00:06:55,940
And then I'm gonna do the same thing for our LoginViewController, and now we have two segue set up.
84

85
00:06:56,460 --> 00:07:02,310
So if you're at all confused about this, then be sure to head back to previous modules or search in the
85

86
00:07:02,310 --> 00:07:03,990
course for segues,
86

87
00:07:04,140 --> 00:07:08,880
because we've covered this in detail before. So I'm not going to waste too much time talking about it
87

88
00:07:08,880 --> 00:07:10,020
again here.
88

89
00:07:10,110 --> 00:07:17,220
Now, the type of segue that I haven't shown you before is a much simpler type of segway because these
89

90
00:07:17,220 --> 00:07:23,460
segue actually connect a view controller to another view controller. So they have to be triggered
90

91
00:07:23,550 --> 00:07:27,210
manually and we do that using the identifier.
91

92
00:07:27,210 --> 00:07:33,240
So you've seen this before as well. But there's another type of segue which is much simpler.
92

93
00:07:33,240 --> 00:07:39,570
We can actually select the register button, hold down the control key on the keyboard, click and drag
93

94
00:07:39,630 --> 00:07:42,480
from it to the register screen.
94

95
00:07:42,960 --> 00:07:50,610
So this way, what we're saying is that we should show the RegisterViewController when the user taps
95

96
00:07:50,730 --> 00:07:56,700
on the register button. And indeed, if you right-click on this button now, you can see that there is now
96

97
00:07:56,760 --> 00:08:03,930
a triggered segue set up so, that whenever this button is tapped, it goes straight to 
97

98
00:08:03,930 --> 00:08:05,290
the RegisterViewController.
98

99
00:08:05,370 --> 00:08:10,070
So let's go ahead and do the same thing for the login screen as well.
99

100
00:08:10,170 --> 00:08:17,580
And now if we go ahead and run our app, then you'll see that when I click on register, it goes to the register
100

101
00:08:17,580 --> 00:08:18,380
screen,
101

102
00:08:18,570 --> 00:08:23,550
and when I click on login, it goes on to the login screen.
102

103
00:08:23,550 --> 00:08:27,560
Now, notice that we're getting what's called a modal transition.
103

104
00:08:27,630 --> 00:08:33,180
So this is a screen that slides up from the bottom and covers the one that's behind.
104

105
00:08:33,180 --> 00:08:41,430
Now, this is not quite the behavior that we want because what we actually want to do is to have a navigation
105

106
00:08:41,430 --> 00:08:42,480
stack,
106

107
00:08:42,780 --> 00:08:50,250
so a way to be able to replace the previous screen with the next screen. Because this way will end up
107

108
00:08:50,250 --> 00:08:57,720
with a navigation bar and will end up with a back button which allows us to go easily back and forth
108

109
00:08:57,750 --> 00:09:03,030
between the welcome screen and each of these register or login screen.
109

110
00:09:03,030 --> 00:09:04,800
Now, how do we do this?
110

111
00:09:05,040 --> 00:09:06,330
Well, it's pretty simple.
111

112
00:09:06,330 --> 00:09:09,730
We select the first view controller.
112

113
00:09:09,870 --> 00:09:15,000
So this is what we would call the route view controller, it's the one that we started from.
113

114
00:09:15,090 --> 00:09:23,790
And we select it again using that yellow button. We go to Editor and then Embed In, and then we select Navigation
114

115
00:09:23,790 --> 00:09:24,510
Controller.
115

116
00:09:25,260 --> 00:09:26,310
And notice how
116

117
00:09:26,310 --> 00:09:34,170
as soon as I do that, you'll see that all of the downstream view controllers get a navigation bar added
117

118
00:09:34,170 --> 00:09:35,950
in completely for free.
118

119
00:09:36,000 --> 00:09:43,500
So we haven't done anything to create these other than embed the route view controller into a navigation
119

120
00:09:43,680 --> 00:09:45,370
controller stack.
120

121
00:09:45,690 --> 00:09:53,460
So, now each of these screens have a back button and the screen has a top navigation bar.
121

122
00:09:53,610 --> 00:10:01,050
And if we run our app again, you'll see that we're able to navigate back and forth and this is the same
122

123
00:10:01,050 --> 00:10:07,170
behavior that you see in a lot of apps like the settings app on your iPhone or the mail app.
123

124
00:10:07,170 --> 00:10:16,050
And this is a really common way of replacing screens with other screens. And creating the navigation
124

125
00:10:16,380 --> 00:10:21,000
for an app that has lots of screens like we have here.
125

126
00:10:21,060 --> 00:10:26,280
So Navigation Stack is a little bit like a stack of pancakes.
126

127
00:10:26,850 --> 00:10:29,330
So I know you guys are missing the food analogies.
127

128
00:10:29,340 --> 00:10:30,250
So this is it.
128

129
00:10:30,260 --> 00:10:31,760
It's coming in right now.
129

130
00:10:31,830 --> 00:10:34,170
Here we've got a stack of three pancakes, right?
130

131
00:10:34,470 --> 00:10:41,010
And in order for me to be able to eat the last pancake, I can't really get to it unless I remove the
131

132
00:10:41,010 --> 00:10:42,360
top two.
132

133
00:10:42,420 --> 00:10:48,570
So the that the Navigation stack works is that for every new screen that's presented, they're stacked
133

134
00:10:48,660 --> 00:10:52,090
on top one another like a stack of pancakes.
134

135
00:10:52,230 --> 00:10:59,040
And in order to get to the bottom one, we have to actually take these off which means these pancakes
135

136
00:10:59,040 --> 00:11:06,870
at the top will get destroyed and dismissed, or eaten, or deallocated memory, whichever term you prefer,
136

137
00:11:07,380 --> 00:11:14,490
and that way, we can actually get to the very, very bottom, pancake or in our case that would be the root
137

138
00:11:14,550 --> 00:11:17,580
view controller which is this screen right here.
138

139
00:11:17,640 --> 00:11:25,140
So, now effectively what I've got is the user will enter on the welcome screen, and then when they click
139

140
00:11:25,140 --> 00:11:30,990
on the register button, that is going to take them to the register screen. When they click on the
140

141
00:11:30,990 --> 00:11:31,770
login button,
141

142
00:11:31,860 --> 00:11:33,890
it's gonna take them to the login screen.
142

143
00:11:34,140 --> 00:11:40,680
And then once they've actually been successful in registering, then do we actually trigger the segue
143

144
00:11:40,980 --> 00:11:42,310
to the table view.
144

145
00:11:42,450 --> 00:11:48,640
And once they've been successful in logging in, do we take them to the chat view as well.
145

146
00:11:48,660 --> 00:11:51,390
So these segues are unconditional, right?
146

147
00:11:51,390 --> 00:11:54,770
It doesn't matter what they've done or if they're authenticated.
147

148
00:11:54,780 --> 00:11:57,600
We don't actually care. As long as they press that button,
148

149
00:11:57,600 --> 00:11:59,530
we take them straight to the screen.
149

150
00:11:59,730 --> 00:12:04,110
But these segues down here, actually depend on something.
150

151
00:12:04,110 --> 00:12:10,380
It depends on whether if they've successfully registered or successfully logged in before we actually
151

152
00:12:10,380 --> 00:12:11,520
trigger these segues.
152

153
00:12:11,880 --> 00:12:17,850
So that's why we've got two different types of segues. And our navigation stack basically allows
153

154
00:12:17,850 --> 00:12:24,300
the user to navigate between these screens in case they've made the wrong decision, say, they've clicked
154

155
00:12:24,300 --> 00:12:28,770
on the register, but actually they've already registered, so they actually need the login,
155

156
00:12:28,770 --> 00:12:29,280
et cetera.
156

157
00:12:29,310 --> 00:12:32,810
So that's a really common sort of pattern that you'll see.
157

158
00:12:33,380 --> 00:12:37,400
And this is the reason why we're getting some warnings about these two segues.
158

159
00:12:37,500 --> 00:12:43,440
So you can see when I click here on the warnings, it's highlighting this segue and this segue, but not
159

160
00:12:43,470 --> 00:12:50,460
any of these, because these don't need an identifier, they are automatically going to be triggered from
160

161
00:12:50,460 --> 00:12:51,480
the buttons.
161

162
00:12:51,660 --> 00:12:56,340
So these ones need an identifier, so that we can trigger it from our code.
162

163
00:12:56,850 --> 00:13:02,030
So the first one I'm going to call RegisterToChat.
163

164
00:13:02,040 --> 00:13:08,610
So this is from the register screen to the chat screen. And make sure that you've spelled it exactly the
164

165
00:13:08,610 --> 00:13:10,500
same way as I've got it here,
165

166
00:13:10,530 --> 00:13:14,440
so that further down the line, we won't end up with any problem of mismatch.
166

167
00:13:15,110 --> 00:13:19,590
So let's hit enter on that one. You'll see one of the warnings disappear.
167

168
00:13:19,790 --> 00:13:27,370
And then this one, this is going to be called LoginToChat. And notice how login, the "I," I've kept lowercase.
168

169
00:13:27,380 --> 00:13:32,200
So, again, make sure that you've got exactly the same spelling as I've got here.
169

170
00:13:32,240 --> 00:13:38,530
So, now when we hit enter and activate that, then we should be able to clear our warnings.
170

171
00:13:38,540 --> 00:13:46,640
So, now if you hit command B to rebuild our app and refresh those warnings, then all of the ones that
171

172
00:13:46,640 --> 00:13:49,070
shouldn't be there anymore should get cleared.
172

173
00:13:49,070 --> 00:13:57,170
And we've now gotten to our starting point and we're ready to create some functionality in our app.
173

174
00:13:57,170 --> 00:13:58,120
In the next lesson,
174

175
00:13:58,160 --> 00:14:04,340
we're going to be adding some animation to our title here, the FlashChat title. And in order to do that,
175

176
00:14:04,370 --> 00:14:06,440
we're going to be learning about Swift loops.
176

177
00:14:06,530 --> 00:14:09,520
So all of that and more, I'll see you on the next lesson.
