0
1
00:00:00,920 --> 00:00:06,980
Now, in the last lesson, we've managed to brighten up our categor's view controller by assigning some
1

2
00:00:07,040 --> 00:00:10,280
random colors to the background of the cells.
2

3
00:00:10,370 --> 00:00:16,190
And we're persisting this data, so that every single time we open up our app or we add a new category,
3

4
00:00:16,460 --> 00:00:20,040
the color stays consistent for each of the categories.
4

5
00:00:20,060 --> 00:00:27,380
So the next thing I want to do is I want to go to the items or the TodoListViewController and I
5

6
00:00:27,380 --> 00:00:29,590
want to create a slightly different effect.
6

7
00:00:29,600 --> 00:00:35,150
I want to create a gradient effect so that, maybe, at the top, we've got one color say, blue, right? And it's
7

8
00:00:35,150 --> 00:00:36,060
light blue.
8

9
00:00:36,320 --> 00:00:42,650
And then through a gradient, all the items get progressively darker and darker and darker, and it'll look
9

10
00:00:42,650 --> 00:00:44,620
like a nice gradient transition.
10

11
00:00:44,840 --> 00:00:47,740
So let's try and see if we can figure out how to do that.
11

12
00:00:47,810 --> 00:00:53,690
Now, back in the Chameleon Framework Documentation, you can see that they have some methods that allow
12

13
00:00:53,690 --> 00:01:02,180
you to color a shade lighter or darker, so that will probably help us to achieve our goals.
13

14
00:01:02,300 --> 00:01:08,990
So let's go into our TodoListViewController and go to the place where it makes the most sense
14

15
00:01:09,110 --> 00:01:15,450
to change the background color of the cell which is, of course, inside cellForRowAt indexPath again.
15

16
00:01:15,470 --> 00:01:21,290
Now, the place where we change the cell properties here is inside this "if-let" and we change the
16

17
00:01:21,290 --> 00:01:22,320
textLabel's text
17

18
00:01:22,370 --> 00:01:26,710
and we're also going to change the cell's background color.
18

19
00:01:26,870 --> 00:01:34,490
So we're going to set the background color depending on the current indexPath. If the indexPath is,
19

20
00:01:34,580 --> 00:01:40,670
say, 0, like the first cell, then we're not going to darken the color by very much. But if the indexPath
20

21
00:01:40,670 --> 00:01:46,020
is much higher, say, at, you know, the tenth row, then we're going to darken it a lot more.
21

22
00:01:46,280 --> 00:01:54,020
So it makes sense if we can change that darkening percentage based on our item number in all of the
22

23
00:01:54,020 --> 00:01:54,920
todoItems.
23

24
00:01:54,920 --> 00:02:00,010
So, say, if we had 10 todoItems, then we want the first item to be darkened by 10 percent.
24

25
00:02:00,080 --> 00:02:07,250
The fifth item to be darkened by 50 percent and the last item to be darkened by, maybe, say, 100 percent.
25

26
00:02:07,250 --> 00:02:13,700
So that way we get a nice gradient transition from the top item all the way down to the bottom item.
26

27
00:02:14,150 --> 00:02:18,530
And we can start doing that by setting the sales background color to--
27

28
00:02:18,650 --> 00:02:25,200
Let's just pick one from Chameleon Framework, maybe something like Flat Sky Blue, right?
28

29
00:02:25,220 --> 00:02:26,320
It looks pretty nice.
29

30
00:02:26,600 --> 00:02:35,670
So we can say that cell's backgroundColor = flatSkyBlue. And in order to get this color out of
30

31
00:02:35,710 --> 00:02:41,650
Chameleon Framework, we, of course, have to remember to import it.
31

32
00:02:41,730 --> 00:02:47,140
So there's a FlatSkyBlue. And we're going to say darken
32

33
00:02:47,400 --> 00:02:55,160
this color by a percentage. And the percentage is going to take a CGFloat,
33

34
00:02:55,170 --> 00:02:58,160
so that's a floating point or decimal number.
34

35
00:02:58,470 --> 00:03:04,830
And the way that this works is it takes a number between 0 and 1, where one is basically 100 percent
35

36
00:03:04,860 --> 00:03:12,630
and 0 is zero percent, and everything in between is your percentage as a CGFloat orCore Graphics floating
36

37
00:03:12,630 --> 00:03:13,930
point number.
37

38
00:03:14,040 --> 00:03:20,470
So the percentage that we want to darken our background color depends on two things.
38

39
00:03:20,640 --> 00:03:25,810
One is which item are we currently trying to color up.
39

40
00:03:25,950 --> 00:03:30,940
And the second thing is how many items are they in our todoList.
40

41
00:03:30,960 --> 00:03:37,380
So let's delete this placeholder and give ourselves a bit of space in order to write out the maths.
41

42
00:03:37,620 --> 00:03:43,470
So the percentage that we're going to darken our cell is going to be the current indexPath.row.
42

43
00:03:43,540 --> 00:03:48,960
Say, if we're currently on the fifth row, right? Let's just imagine one particular situation, rather than
43

44
00:03:49,230 --> 00:03:56,530
trying to plan for all the scenarios. We're currently on row number, number five, right?
44

45
00:03:56,730 --> 00:04:09,130
And there's a total of 10 items in todoItems. So, now we're on 5 out of 10.
45

46
00:04:09,160 --> 00:04:15,970
So we want to darken our background color by, basically, 50 percent, so close to 0.5,
46

47
00:04:15,970 --> 00:04:22,080
and we can get that number by dividing the indexPath.row by the total number of items, right?
47

48
00:04:22,090 --> 00:04:24,970
So todoItems.count.
48

49
00:04:25,130 --> 00:04:28,900
Now, indexPath.row is going to be an integer
49

50
00:04:29,080 --> 00:04:34,220
and todoItems.count is also going to be an integer.
50

51
00:04:34,300 --> 00:04:36,170
So integer divided by integer,
51

52
00:04:36,190 --> 00:04:37,820
that's perfectly valid.
52

53
00:04:37,930 --> 00:04:45,150
But we need to get it out as a CGFloat in order to satisfy the requirements of this particular parameter.
53

54
00:04:45,250 --> 00:04:49,330
So we can cast it into a CGFloat
54

55
00:04:49,330 --> 00:04:56,260
or you might think we can. This line of code will make sense to the largest number of people. But I'm
55

56
00:04:56,260 --> 00:04:58,510
going to show you what happens when we do this
56

57
00:04:58,540 --> 00:05:02,980
and you might already be able to predict if you are good with the logic, and you've been keeping up with
57

58
00:05:02,980 --> 00:05:04,640
what I've been saying. But no matter,
58

59
00:05:04,690 --> 00:05:07,150
this line makes sense to us, right?
59

60
00:05:07,150 --> 00:05:11,690
Take the current indexPath.row which is five, divided by 10,
60

61
00:05:11,740 --> 00:05:14,470
you get 0.5.
61

62
00:05:14,470 --> 00:05:20,430
And 0.5 works as a floating point percentage to darken our FlatSkyBlue color.
62

63
00:05:20,560 --> 00:05:26,330
Now, all of this code, remember, gets called for every single cell in the tableView.
63

64
00:05:26,380 --> 00:05:33,880
So when we are on row number one out of 10 items, then this is going to be 0.1.
64

65
00:05:33,880 --> 00:05:38,830
And so we're only going to darken our backgroundColor by 10 percent.
65

66
00:05:38,830 --> 00:05:47,680
Now, the problem as Xcode is suggesting to us, is that this darkoen byPercentage method returns an optional
66

67
00:05:47,800 --> 00:05:53,110
UIColor, but this needs a definite UIColor.
67

68
00:05:53,170 --> 00:05:54,870
So what can we do?
68

69
00:05:55,000 --> 00:06:02,830
Well, we can, of course, use our handy "if-let," and you can see that we are now building a optional binding
69

70
00:06:02,830 --> 00:06:09,760
pyramid. And this pattern, unfortunately, is a bit too common in Swift.
70

71
00:06:09,760 --> 00:06:16,940
So if let colour equal all of this,
71

72
00:06:17,070 --> 00:06:20,270
so let's cut it and paste it.
72

73
00:06:20,340 --> 00:06:26,810
Now, we can, of course, shorten this if we don't want all of that extra commenting.
73

74
00:06:26,820 --> 00:06:33,510
You can see that we can actually make it all fit into one line. At this point, it's telling us that your
74

75
00:06:33,670 --> 00:06:37,750
optionally chaining todoItems here using this question mark.
75

76
00:06:37,770 --> 00:06:43,450
So this is saying get the count if todoItems is not nil.
76

77
00:06:43,590 --> 00:06:47,400
Now, we know that todoItems can't be nil
77

78
00:06:47,550 --> 00:06:54,510
inside this current if-let because it's only going to get called if todoItems an indexPath.row
78

79
00:06:54,570 --> 00:06:55,690
is not nil.
79

80
00:06:55,740 --> 00:07:02,730
So this is a place where it's actually safe to simply force unwrap, force unwrap todoItems.
80

81
00:07:02,760 --> 00:07:12,750
So if like let colour equal this darker color, then what we should do is we should set the cell's 
81

82
00:07:12,750 --> 00:07:15,310
backgroundColor to this color.
82

83
00:07:15,440 --> 00:07:19,240
And now, if we run our app, you'll see something slightly peculiar happened.
83

84
00:07:19,500 --> 00:07:24,920
So let's go into our Home category and let's add some items, shall we?
84

85
00:07:25,710 --> 00:07:31,330
Buy Food. Eat food.
85

86
00:07:34,140 --> 00:07:35,380
Enjoy Food.
86

87
00:07:38,090 --> 00:07:41,360
I'm getting a peek into my mindset here.
87

88
00:07:41,660 --> 00:07:42,500
All right, so--
88

89
00:07:42,650 --> 00:07:44,870
Oh, there's still the separators over here, right?
89

90
00:07:44,870 --> 00:07:52,500
So let's get rid of the separators by putting it inside viewDidLoad, tableView.separateStyle
90

91
00:07:52,510 --> 00:07:55,770
= .none.
91

92
00:07:55,790 --> 00:07:58,070
So we'll run that change a little bit later on.
92

93
00:07:58,130 --> 00:08:08,240
But the more pertinent problem is, why on earth do we have the same colors, even though we told our code
93

94
00:08:08,510 --> 00:08:14,960
to darken this FlatSkyBlue color by a percentage depending on which row we're on.
94

95
00:08:14,960 --> 00:08:17,160
So we're expecting a gradient here,
95

96
00:08:17,180 --> 00:08:17,480
right?
96

97
00:08:17,480 --> 00:08:18,890
That would be nice.
97

98
00:08:18,890 --> 00:08:25,770
So here is a fundamental logical mathematical issue with type conversions.
98

99
00:08:25,820 --> 00:08:28,180
So I'm going to print two things here.
99

100
00:08:28,400 --> 00:08:36,560
I'm going to print, say, "version 1" and version 1 is going to be what we've got here.
100

101
00:08:36,840 --> 00:08:44,000
indexPath.row / todoItems.count, and then the result of that division turned into
101

102
00:08:44,030 --> 00:08:45,230
a CGFloat.
102

103
00:08:46,710 --> 00:08:52,830
And the second version or "version 2" is going to be slightly different.
103

104
00:08:52,830 --> 00:09:04,140
What if we first turn indexPath.row into a CGFloat by casting it, and then after we've turned
104

105
00:09:04,140 --> 00:09:09,240
it into a float, do we divide it by todoItems.count,
105

106
00:09:09,540 --> 00:09:13,500
And because we can only do division between similar types,
106

107
00:09:13,590 --> 00:09:13,900
right,
107

108
00:09:13,950 --> 00:09:17,980
as it says, "Binary operator / cannot be applied to different types,"
108

109
00:09:18,060 --> 00:09:25,650
then we're also going to convert todoItems.count into a CGFloat as well.
109

110
00:09:25,650 --> 00:09:32,660
So the important difference between version 1 and version 2, is that version 1
110

111
00:09:32,700 --> 00:09:39,810
we're doing whole number divided by a whole number, and the result gets turned into a CGFloat,
111

112
00:09:39,810 --> 00:09:45,660
version 2 is whole number gets turned into a CGFloat, whole number gets turned into a CGFloat,
112

113
00:09:45,750 --> 00:09:48,970
then CGFloats are divided by CGFloats.
113

114
00:09:49,020 --> 00:09:56,900
So let's go ahead and hit run and see what we get printed out for every single row in our table view.
114

115
00:09:57,120 --> 00:10:00,550
So let's, again, go into Home where we've already got three items,
115

116
00:10:00,960 --> 00:10:03,090
and let's take a look over here.
116

117
00:10:03,210 --> 00:10:11,910
So version 1 for the first row, indexPath is 0, 0 divided by 3 is still going to be 0,
117

118
00:10:11,910 --> 00:10:14,880
so both of them are 0.0.
118

119
00:10:15,210 --> 00:10:23,880
Now, the differences come in the second row where the index top row is equal to 1. 1 divided by 3 is a
119

120
00:10:23,880 --> 00:10:26,180
third or 0.3 recurring.
120

121
00:10:26,460 --> 00:10:34,290
But that only gets shown in our second version, not our first version. Our first version is still 0.
121

122
00:10:34,290 --> 00:10:36,150
Now why is that?
122

123
00:10:36,150 --> 00:10:44,730
Well, when you divide a whole number by a whole number, the output here gets rounded into a whole number,
123

124
00:10:45,090 --> 00:10:49,730
and then that rounded whole number gets turned into a floating point.
124

125
00:10:49,800 --> 00:10:57,330
So you can try it yourself inside Swift Playgrounds, but this is, essentially, the reason why our code
125

126
00:10:57,330 --> 00:10:58,140
does not work.
126

127
00:10:58,140 --> 00:11:03,270
And this is a very, very simple reason why sometimes when you work with floats and doubles, and trying to
127

128
00:11:03,270 --> 00:11:08,130
use variables that are integers, you might get unexpected problems.
128

129
00:11:08,130 --> 00:11:14,700
So this is something that happens to a lot of people and we're simply going to replace that inside here
129

130
00:11:14,730 --> 00:11:17,910
where it says byPercentage.
130

131
00:11:18,330 --> 00:11:24,350
Okay. So, now I'm going to comment out my print statements because we no longer need them. And I'm going
131

132
00:11:24,350 --> 00:11:25,460
to run our app
132

133
00:11:25,550 --> 00:11:27,950
and we are going to hope for the best.
133

134
00:11:27,950 --> 00:11:28,210
All right.
134

135
00:11:28,220 --> 00:11:31,650
So let's go inside Home, and dun-dud-dun,
135

136
00:11:32,030 --> 00:11:33,370
Isn't that cool?
136

137
00:11:33,380 --> 00:11:37,250
And as we add more items--
137

138
00:11:37,340 --> 00:11:40,050
I don't know. "Eat more food."
138

139
00:11:40,280 --> 00:11:42,130
"I'm so hungry."
139

140
00:11:43,920 --> 00:11:46,290
"Feed me."
140

141
00:11:46,530 --> 00:11:53,220
You can see the gradient starts building up, and depending on which road we're on, it will darken it by
141

142
00:11:53,220 --> 00:11:59,510
the percentage determined by which row it is in the total number of items.
142

143
00:11:59,520 --> 00:12:02,430
So this is looking pretty neat, right?
143

144
00:12:04,840 --> 00:12:13,600
Now, there's just one problem, and the problem is that this part gets so dark that we can't actually see
144

145
00:12:13,600 --> 00:12:14,850
the text anymore.
145

146
00:12:15,010 --> 00:12:17,390
Yeah, it looks pretty neat and it's pretty.
146

147
00:12:17,410 --> 00:12:21,970
But as we always say, you should choose function over form,
147

148
00:12:22,000 --> 00:12:22,670
right?
148

149
00:12:22,720 --> 00:12:24,310
Unless we can have both.
149

150
00:12:24,310 --> 00:12:28,640
So what do we need to happen in order for our app to work well?
150

151
00:12:28,870 --> 00:12:36,670
Well, we will need the text for the darker backgrounds to be white instead of black, and the text for
151

152
00:12:36,670 --> 00:12:39,660
the lighter backgrounds to be black instead of white,
152

153
00:12:39,670 --> 00:12:41,660
so how can we do this?
153

154
00:12:41,880 --> 00:12:48,210
Well, we can either Google for it and look through custom solutions or why don't we just see if Chameleon
154

155
00:12:48,220 --> 00:12:51,090
Framework already has a method that does it.
155

156
00:12:51,190 --> 00:12:56,730
If it doesn't, we'll build a custom solution. But if it does, let's not reinvent the wheel.
156

157
00:12:56,980 --> 00:13:03,550
And if you scroll through that documentation, you'll come across this neat little thing called contrasting
157

158
00:13:03,580 --> 00:13:09,290
text. And it means that you no longer have to worry about the text
158

159
00:13:09,370 --> 00:13:14,080
standing out from the background color because it's going to take care of it for you.
159

160
00:13:14,200 --> 00:13:17,170
So let's try and figure out where it allows us to do that.
160

161
00:13:17,170 --> 00:13:26,140
So I'm just going to go for command F to find contrasting text. Contrasting Text. Contrasting colors.
161

162
00:13:26,250 --> 00:13:31,960
Okay. So this contrasting color feature returns either a dark color or light color depending on what
162

163
00:13:31,960 --> 00:13:35,610
the Chameleon algorithm believes is a better choice.
163

164
00:13:35,650 --> 00:13:42,480
And we can use it by using UIColor(contrastingBlackOrWhiteColorOn:UIColor, isFlat,
164

165
00:13:42,550 --> 00:13:43,420
true or false,
165

166
00:13:43,540 --> 00:13:49,840
or we can just use the shorthand contrast color passing in the current background color and specifying
166

167
00:13:49,840 --> 00:13:52,490
whether it should be flat or not flat.
167

168
00:13:52,510 --> 00:13:55,880
So let's go ahead and implement that in our code.
168

169
00:13:56,140 --> 00:14:02,410
So inside the same place where we did the optional binding, where we specify the background color, we're
169

170
00:14:02,410 --> 00:14:11,650
going to change the cell's textLabel.textColor. And that textColor is going to be equal to 
170

171
00:14:11,950 --> 00:14:15,400
ContrastColorOf backgroundColor.
171

172
00:14:15,400 --> 00:14:22,000
So we're going to pass in our backgroundColor that we generated up here and return a flat color or not
172

173
00:14:22,000 --> 00:14:22,930
a flat color,
173

174
00:14:22,930 --> 00:14:24,240
we're going to set equal
174

175
00:14:24,280 --> 00:14:25,140
true.
175

176
00:14:25,450 --> 00:14:28,240
And now let's run our app and see the magic happen.
176

177
00:14:31,020 --> 00:14:31,770
Nice, right?
177

178
00:14:32,220 --> 00:14:33,990
Looks pretty sweet.
178

179
00:14:33,990 --> 00:14:40,380
Now, you can see that they're all white because the flat sky blue is a little bit dark of a color by
179

180
00:14:40,380 --> 00:14:43,610
itself, and the white stands out quite nicely against it.
180

181
00:14:43,620 --> 00:14:49,260
So this algorithm behind the scenes is trying to figure out whether it's white or black is the more
181

182
00:14:49,260 --> 00:14:50,650
optimal choice.
182

183
00:14:50,670 --> 00:14:58,020
So if we went for a slightly lighter color from the palette, instead of flat sky blue, say, something like, I don't know,
183

184
00:14:58,800 --> 00:14:59,870
a flat white,
184

185
00:14:59,910 --> 00:15:00,590
right?
185

186
00:15:01,050 --> 00:15:03,830
Let's try that one, FlatWhite.
186

187
00:15:06,930 --> 00:15:08,960
This is making me want coffee now.
187

188
00:15:09,220 --> 00:15:17,590
Okay, so let's go ahead and hit run. And you can see that, automatically, the lighter colors at the top were
188

189
00:15:17,590 --> 00:15:22,930
given black text colors, and the darker colors at the bottom were given white text colors.
189

190
00:15:22,990 --> 00:15:26,830
So it's pretty neat, right? Now, it's all very well and good
190

191
00:15:26,830 --> 00:15:31,930
specifying a color and getting it darkened by percentage.
191

192
00:15:31,930 --> 00:15:39,310
Wouldn't it be nice if you could carry through the color of the category, so the user will select Home
192

193
00:15:39,760 --> 00:15:45,800
and this will be a gradient of green colors similar to our Home color.
193

194
00:15:45,820 --> 00:15:54,740
So what you'll need to do is to, somehow, change this to the color that we persisted using Realm.
194

195
00:15:54,870 --> 00:16:00,130
So pause the video and try and see if you can complete this challenge.
195

196
00:16:00,130 --> 00:16:00,420
All right.
196

197
00:16:00,430 --> 00:16:07,290
So this one shouldn't be too hard because if you remember we passed in the current category using the
197

198
00:16:07,300 --> 00:16:14,230
selectedCategory property, and this is a optional category that contains all the pieces of data in here,
198

199
00:16:14,230 --> 00:16:19,270
so the name of the category, as well as the color of the category as a string.
199

200
00:16:19,270 --> 00:16:29,200
So if we go in here and replace this FlatWhite using something like UIColor, using hexString,
200

201
00:16:31,700 --> 00:16:39,750
and the string is going to come from our selectedCategory.colour property.
201

202
00:16:39,790 --> 00:16:47,750
Now, we've got some problems here because if you click on the error, it says that selectedCategory is--
202

203
00:16:47,930 --> 00:16:51,890
It says that--it tells us that selectedCategory,
203

204
00:16:51,950 --> 00:16:57,020
the first little highlight, is an optional category and it's not unwrapped.
204

205
00:16:57,020 --> 00:17:04,870
The other problem is that the output or the return of this initializer create a UIColor using
205

206
00:17:04,910 --> 00:17:11,520
hexString is also a optional UIColor, and it's also not unwrapped.
206

207
00:17:11,570 --> 00:17:13,690
So there's two ways of solving this.
207

208
00:17:13,760 --> 00:17:17,730
You can either go down a pretty steep if-let pyramid,
208

209
00:17:17,780 --> 00:17:20,600
if let color equals this, 
209

210
00:17:20,600 --> 00:17:21,540
then if let blah-blah-blah.
210

211
00:17:21,830 --> 00:17:23,930
And then if let, the next one,
211

212
00:17:23,930 --> 00:17:28,070
then if let, the next one, unwrapping each property as you go along.
212

213
00:17:28,130 --> 00:17:30,930
But let's go back to first principles
213

214
00:17:30,980 --> 00:17:32,530
where inside this if let
214

215
00:17:32,540 --> 00:17:39,890
at the moment, and checking to see if todoItems at indexPath.row is or is not nil.
215

216
00:17:40,400 --> 00:17:47,270
Now, if this is not nil, then that means that we manage to have items inside todoItems, then that means
216

217
00:17:47,270 --> 00:17:54,020
todoItem exists. And todoItems comes from our selectedCategory which must mean that selectCategory
217

218
00:17:54,020 --> 00:17:55,470
can't be nil either.
218

219
00:17:55,610 --> 00:18:02,990
So sometimes having these warnings forces you, as a human developer, to think and see if this is safe
219

220
00:18:03,080 --> 00:18:04,180
to be unwrapped.
220

221
00:18:04,250 --> 00:18:06,430
Now we've unwrapped selectedCategory.
221

222
00:18:06,650 --> 00:18:13,080
The next thing we need to tackle is, what if we can't actually get a color from this hextString?
222

223
00:18:13,130 --> 00:18:19,280
What if I just entered some piece of, you know, mumbo-jumbo of a hexString, and you can't actually get a
223

224
00:18:19,280 --> 00:18:19,870
hex color?
224

225
00:18:19,880 --> 00:18:24,770
And this is a problem you always have when you allow strings because strings can be free form.
225

226
00:18:24,800 --> 00:18:27,870
It doesn't have to conform to a particular format.
226

227
00:18:27,980 --> 00:18:30,240
Then I could have put in any old string in here.
227

228
00:18:30,500 --> 00:18:34,130
And of course, you can't just generate a color from any string.
228

229
00:18:34,130 --> 00:18:35,460
That's not how it works.
229

230
00:18:35,480 --> 00:18:37,760
It has to be a valid hexString.
230

231
00:18:37,760 --> 00:18:39,860
Now, we don't have any validation for that.
231

232
00:18:39,860 --> 00:18:46,910
But what we can say is if this is nil, then don't go forwards with the next method,
232

233
00:18:46,920 --> 00:18:48,700
i.e., darkened by percentage.
233

234
00:18:48,740 --> 00:18:53,130
So we're saying optionally chain this.
234

235
00:18:53,300 --> 00:19:04,190
So if this is not nil, i.e., we got a valid hex code creating a valid UIColor and it's not nil, then go
235

236
00:19:04,190 --> 00:19:11,740
forwards and try to darken it. Because if we try to darken a nil value, then this is where our app is going
236

237
00:19:11,740 --> 00:19:12,480
to crash.
237

238
00:19:12,560 --> 00:19:20,300
So we're using optional chaining to make sure that all of this is not nil before we continue with our
238

239
00:19:20,300 --> 00:19:21,310
code block.
239

240
00:19:21,710 --> 00:19:29,480
So let's run our app and see if we manage to carry forwards that color from the category to our
240

241
00:19:29,480 --> 00:19:31,140
TodoListViewController.
241

242
00:19:31,160 --> 00:19:31,480
All right.
242

243
00:19:31,490 --> 00:19:39,450
So here's our Home category which is green and if we click on it-- Oh, look. Isn't that nice?
243

244
00:19:39,470 --> 00:19:42,910
We've got a gradient of green items
244

245
00:19:42,950 --> 00:19:49,130
and we've got text that's contrasting with the background color, and it looks pretty neat to me at least.
245

246
00:19:49,130 --> 00:19:51,680
So did you manage to get that to work?
246

247
00:19:51,680 --> 00:19:53,080
If so, then great.
247

248
00:19:53,150 --> 00:19:56,020
If not, then you might need to watch some of the past videos
248

249
00:19:56,040 --> 00:19:57,640
a few more times.
249

250
00:19:57,650 --> 00:19:58,120
All right.
250

251
00:19:58,190 --> 00:20:04,730
In the next lesson, we're going to tidy everything up and we're going to change our nav bar to make it
251

252
00:20:04,730 --> 00:20:07,810
reflect the colors that we've got in our
252

253
00:20:07,810 --> 00:20:08,800
TodoListViewController.
253

254
00:20:09,060 --> 00:20:11,740
So all of that and more, we'll see you on the next lesson.
