1
00:00:08,130 --> 00:00:10,800
Hey buddy this is Caleb with Devon Lopes dot com.

2
00:00:10,830 --> 00:00:14,550
And in this video we're going to be talking about enumerations.

3
00:00:14,550 --> 00:00:18,170
Enumerations are a really cool thing and swift.

4
00:00:18,180 --> 00:00:24,030
It's a type that basically contains a group of related values that are all kind of under the same on

5
00:00:24,030 --> 00:00:25,910
Barela as each other.

6
00:00:25,920 --> 00:00:31,170
So if you think about like a you know car is the big umbrella you might have Maserati Lamborghini Geo

7
00:00:31,170 --> 00:00:32,150
Metro.

8
00:00:32,280 --> 00:00:33,430
Nice.

9
00:00:33,540 --> 00:00:36,690
If you think about fruit you might have banana apple orange.

10
00:00:36,690 --> 00:00:43,220
They're all related values under the same overarching type which is you know a cool way to manage it.

11
00:00:43,500 --> 00:00:50,070
And basically what an enumeration allows us to do is we can work with those values in a type safe way

12
00:00:50,520 --> 00:00:51,560
which is really neat.

13
00:00:51,720 --> 00:00:56,730
So to show you how this works I'm actually going to go ahead and create a playground and we're going

14
00:00:56,730 --> 00:01:00,520
to go ahead and I'm going to teach you the syntax of an enumeration.

15
00:01:00,900 --> 00:01:04,710
I'm going to show you a couple of different things you can do with enumerations and then at the very

16
00:01:04,710 --> 00:01:10,260
end I'm going to show you a practical example that you could actually use in an application so you know

17
00:01:10,260 --> 00:01:11,430
how you can use this.

18
00:01:11,430 --> 00:01:15,930
So let's go ahead and click get started with the playground and it should pop up.

19
00:01:15,930 --> 00:01:17,530
Popped up on my other window here.

20
00:01:17,640 --> 00:01:22,230
But for now let's create a blank playground and I'm just going to name it.

21
00:01:22,440 --> 00:01:28,920
You know as a teacher I'm the teacher you can name it whatever you want and go ahead and bump that open

22
00:01:28,920 --> 00:01:30,340
into fullscreen.

23
00:01:30,870 --> 00:01:32,600
And we're going to go ahead.

24
00:01:32,850 --> 00:01:34,640
You know what this might be an X code beta bug.

25
00:01:34,650 --> 00:01:38,650
It looks like we're not going to be able to stretch that any wider but that's fine.

26
00:01:38,910 --> 00:01:44,160
So for now let's get rid of that string there we don't need it let's get rid of the boilerplate code

27
00:01:44,760 --> 00:01:46,180
and let's begin.

28
00:01:46,500 --> 00:01:52,420
So the syntax of an enumeration goes like this you declare it by typing inam.

29
00:01:52,500 --> 00:01:54,640
OK that's short for enumeration.

30
00:01:54,900 --> 00:02:00,190
And then you give it a name and think of these names like you would name a class.

31
00:02:00,200 --> 00:02:04,510
OK so you're going to use capital letters at the very beginning for every word.

32
00:02:04,530 --> 00:02:05,840
It will have a capital.

33
00:02:05,840 --> 00:02:10,390
So just for example name of them.

34
00:02:10,710 --> 00:02:14,090
And then you're going to give it some curly braces just like a class.

35
00:02:14,130 --> 00:02:19,910
Now inside an enumeration we're going to go ahead and we're going to set up cases.

36
00:02:19,920 --> 00:02:20,520
OK.

37
00:02:20,760 --> 00:02:26,670
If you've ever used a switch statement you're familiar with these a switch basically allows you to go

38
00:02:26,670 --> 00:02:31,700
through a bunch of different options and you call each one of those options a case.

39
00:02:31,800 --> 00:02:38,010
And so for an enumeration we're going to give it cases as well so I'm just going to say case case one

40
00:02:38,640 --> 00:02:43,140
case case to case case three.

41
00:02:43,210 --> 00:02:43,660
OK.

42
00:02:43,680 --> 00:02:47,300
Now of course these would be named something differently in a different enumeration.

43
00:02:47,310 --> 00:02:49,180
But for now this is just an example.

44
00:02:49,260 --> 00:02:53,680
And as you can see the enumeration has three separate cases.

45
00:02:53,850 --> 00:03:02,700
And in order to instantiate that all you need to do is to set up let in numeration and we can make it

46
00:03:02,730 --> 00:03:03,760
of type.

47
00:03:04,110 --> 00:03:08,250
Well actually let's do a call in there make it of type name of a name.

48
00:03:08,280 --> 00:03:12,570
This of course is a terrible name but it's just for an example I'll show you some real examples in a

49
00:03:12,570 --> 00:03:13,310
second.

50
00:03:13,590 --> 00:03:16,760
And we can set that to be equal to one of our cases.

51
00:03:16,830 --> 00:03:20,000
Ok I'll show you why this is useful in just a little bit.

52
00:03:20,160 --> 00:03:22,750
Now to actually access these cases I can't just type.

53
00:03:22,750 --> 00:03:25,070
Case one you'll see it doesn't pop up.

54
00:03:25,320 --> 00:03:31,680
But what I can do is I can type a period and that will give me access to all three of the different

55
00:03:31,680 --> 00:03:32,640
cases that I've set.

56
00:03:32,640 --> 00:03:35,300
So let's set this to be equal to case two.

57
00:03:35,550 --> 00:03:39,420
And now you can see its value on the screen there is set to be case to.

58
00:03:39,800 --> 00:03:40,870
That's pretty cool.

59
00:03:41,190 --> 00:03:48,000
So this is the basic syntax of an enumeration you declare with ENM and you give it cases OK.

60
00:03:48,210 --> 00:03:56,010
Like I said before Karr could be the name of the enim and the cases could be DeLorean Maserati Lamborghini

61
00:03:56,220 --> 00:03:58,180
Cato's could be all the different cases.

62
00:03:58,260 --> 00:04:01,680
Now you don't have to declare each case on a separate line.

63
00:04:01,800 --> 00:04:04,470
You can actually just go ahead and use commas.

64
00:04:04,530 --> 00:04:04,760
OK.

65
00:04:04,770 --> 00:04:10,410
Just like when you create multiple constants or variables you can declare them in one straight line

66
00:04:10,410 --> 00:04:11,450
by using commas.

67
00:04:11,490 --> 00:04:17,060
So just type case one comma case two comma case three.

68
00:04:17,310 --> 00:04:19,960
And as you can see that works just the same.

69
00:04:20,100 --> 00:04:21,570
Ok pretty cool.

70
00:04:21,570 --> 00:04:23,940
So let's go ahead and let's move on.

71
00:04:23,940 --> 00:04:25,610
I'm going to show you some other cool things.

72
00:04:25,630 --> 00:04:27,210
Enumerations can do.

73
00:04:27,510 --> 00:04:31,610
And one of those things actually is a really great example from Apple.

74
00:04:31,740 --> 00:04:37,440
So I'm going to pull open these two bar codes here and barcodes are a great example because enumerations

75
00:04:37,440 --> 00:04:44,910
allow us to work with related values but they also are good for kind of differentiating different types

76
00:04:44,940 --> 00:04:45,870
of things.

77
00:04:45,930 --> 00:04:53,340
And so here we have a standard UPC product bar code and we also have a QR code which is used for you

78
00:04:53,340 --> 00:04:56,670
know all kinds of different things storing all kinds of different information.

79
00:04:56,670 --> 00:05:01,890
So there are very different kinds of barcodes but they are both barcodes.

80
00:05:01,890 --> 00:05:07,420
So we're going to create an enumeration for barcode but we're going to give it to cases one will be

81
00:05:07,480 --> 00:05:13,300
UPC OK like this one here that you'd see on like the back of a box of cereal or something and then we'll

82
00:05:13,300 --> 00:05:15,310
create one for the QR code.

83
00:05:15,310 --> 00:05:21,310
So go ahead and type ENM barcode and we're going to give it two cases.

84
00:05:21,370 --> 00:05:24,720
The first case will be case UPC.

85
00:05:24,790 --> 00:05:31,760
The second will be case wups case and Q are code just like that.

86
00:05:31,810 --> 00:05:38,090
Now we're going to be able to put in associated values into this barcode enumeration.

87
00:05:38,230 --> 00:05:43,300
And what that's going to allow us to do is whenever we create an instance of barcode.

88
00:05:43,450 --> 00:05:49,540
And let's just say that we create an instance of barcode UPC will be able to pass in values that are

89
00:05:49,540 --> 00:05:53,130
associated with that and then use those later or modify them.

90
00:05:53,130 --> 00:05:54,110
It's really cool.

91
00:05:54,310 --> 00:06:00,160
So for a UPC for a product barcode you'll notice there are four different numbers.

92
00:06:00,160 --> 00:06:07,180
Now at the beginning there is a number that denotes the specific number system k that a certain product

93
00:06:07,360 --> 00:06:08,860
might use.

94
00:06:09,190 --> 00:06:15,480
The second set of numbers is to denote the manufacturer who makes the product.

95
00:06:15,490 --> 00:06:19,680
Third is the product name or the product value.

96
00:06:19,690 --> 00:06:24,850
Basically these numbers are associated with a specific product and then at the very end there's what's

97
00:06:24,850 --> 00:06:31,390
called a check and that basically allows for the store to know whether or not the barcode was scanned

98
00:06:31,450 --> 00:06:32,270
successfully.

99
00:06:32,280 --> 00:06:32,790
OK.

100
00:06:33,070 --> 00:06:34,530
So there are four values.

101
00:06:34,600 --> 00:06:39,760
And what we're going to do is we're actually going to just put a parentheses next to you PC and we can

102
00:06:39,760 --> 00:06:47,830
pass in four separate values in a couple which a couple is as you know a list of values unrelated or

103
00:06:47,830 --> 00:06:48,350
related.

104
00:06:48,360 --> 00:06:48,610
OK.

105
00:06:48,640 --> 00:06:49,940
That can be either.

106
00:06:50,050 --> 00:06:54,520
Now the values in this table are going to be related and it's actually going to just be for integers

107
00:06:55,050 --> 00:06:57,940
one for each of the separate number values and our barcode.

108
00:06:57,940 --> 00:07:03,910
So go ahead and just type int comma int and do that four times like so.

109
00:07:03,910 --> 00:07:05,280
And for the QR code.

110
00:07:05,350 --> 00:07:10,930
The cool thing is a QR code can hold all kinds of information and data actually up to like two thousand

111
00:07:10,930 --> 00:07:13,280
nine hundred fifty characters or something.

112
00:07:13,600 --> 00:07:18,040
But what we're going to do is instead of passing multiple values we're just going to pass in one string

113
00:07:18,040 --> 00:07:25,240
value because oftentimes QR codes hold textual data K like a U R L or account information.

114
00:07:25,590 --> 00:07:25,870
OK.

115
00:07:25,870 --> 00:07:26,700
Very cool.

116
00:07:26,710 --> 00:07:32,650
So now that we have these associated values with our enumeration what we're going to be able to do is

117
00:07:32,650 --> 00:07:36,740
create an instance of it and pass in those values and then we can use them later on.

118
00:07:36,760 --> 00:07:43,390
So let's go ahead and let's create a barcode by typing var product barcode and we're going to set that

119
00:07:43,390 --> 00:07:44,980
to be equal to Barka.

120
00:07:45,490 --> 00:07:51,480
And if we push the little if we give a period there we can choose UPC or QR code.

121
00:07:51,580 --> 00:07:53,660
OK let's choose a UPC for now.

122
00:07:53,920 --> 00:07:58,900
And as you can see it looks a little bit like a function we're passing in values and we're basically

123
00:07:58,900 --> 00:08:04,250
just setting them as for little temporary variables inside of this barcode.

124
00:08:04,240 --> 00:08:08,420
So let's go ahead and let's give the values from our UPC here.

125
00:08:08,470 --> 00:08:15,040
So the manufacturer is or sorry the what's it called the number system is what the manufacturer is 8

126
00:08:15,100 --> 00:08:21,770
5 9 0 9 the product number is 5 1 2 2 6 and the check number is 3.

127
00:08:21,940 --> 00:08:25,510
So that's cool and all but what if I wanted to print this out if I type.

128
00:08:25,510 --> 00:08:27,600
Print product barcode.

129
00:08:27,640 --> 00:08:28,570
Watch what happens.

130
00:08:28,600 --> 00:08:31,470
It will print down here at the bottom in just a moment.

131
00:08:33,550 --> 00:08:37,380
So as you can see it prints out UPC and it prints out our four values.

132
00:08:37,390 --> 00:08:41,920
That's pretty cool but we can't exactly access them or pull them out in any way as you see.

133
00:08:41,920 --> 00:08:44,640
Nothing pops up when I type a period at the end of that.

134
00:08:44,800 --> 00:08:47,590
So we can't actually access it that way.

135
00:08:47,830 --> 00:08:49,910
But check out what we can do.

136
00:08:50,020 --> 00:08:55,990
We can create a switch statement and we're going to pass our bar code in and if it is a PC we're going

137
00:08:55,990 --> 00:09:01,660
to create a temporary constant and we're going to assign four constant values to the four values in

138
00:09:01,660 --> 00:09:04,570
our UPC then we can work with them and modify them.

139
00:09:04,570 --> 00:09:09,170
So let's go ahead and let's create a switch statement for product barcode.

140
00:09:09,610 --> 00:09:10,110
OK.

141
00:09:10,120 --> 00:09:13,600
And we're going to give it to cases UPC or QR code.

142
00:09:13,840 --> 00:09:19,580
So go ahead and type case and the only thing by the way since it is of type barcode The only things

143
00:09:19,580 --> 00:09:23,590
that can be are a UPC or a QR code.

144
00:09:23,650 --> 00:09:29,200
So we're going to go ahead and create some constants here so inciter switch statement here we're going

145
00:09:29,200 --> 00:09:33,950
to go ahead and create four constants by typing let dot UPC.

146
00:09:34,150 --> 00:09:40,180
So we're basically saying for a PC we're going to set four constants for these four values and to do

147
00:09:40,180 --> 00:09:46,850
that go ahead and type parentheses and just like I said we're going to type number system.

148
00:09:47,050 --> 00:09:48,520
That's the first number.

149
00:09:48,520 --> 00:09:55,770
Then the manufacturer then the product then the end is a check.

150
00:09:55,950 --> 00:09:56,470
OK.

151
00:09:56,770 --> 00:10:02,920
Now we're using Let here and just like we did up here with the three cases on the same line by typing

152
00:10:02,920 --> 00:10:08,060
let here and number system manufacturer product check we're creating four separate constants.

153
00:10:08,230 --> 00:10:12,290
And what we're going to do is once we have those four values set we can print them out.

154
00:10:12,310 --> 00:10:22,380
So print and whoops we're going to go ahead and print UPC and then using string interpolation we're

155
00:10:22,430 --> 00:10:29,170
gonna go ahead and pass these four constants we've created in and see if the values get properly passed.

156
00:10:29,170 --> 00:10:35,140
So inside of our special string interpellation syntax go ahead and type number system and then you know

157
00:10:35,140 --> 00:10:35,280
what.

158
00:10:35,290 --> 00:10:40,930
Let's actually before we type that let's copy and paste this so we don't have to type it so many times.

159
00:10:40,930 --> 00:10:41,390
There we go.

160
00:10:41,410 --> 00:10:43,300
So let's print number system.

161
00:10:43,690 --> 00:10:52,570
OK then let's print manufacturer then product Whoops you know what let's call that product code.

162
00:10:52,570 --> 00:10:56,270
Actually I like that better product code.

163
00:10:56,320 --> 00:10:58,500
And at the end we're going to print the check value.

164
00:10:58,570 --> 00:11:03,760
So watch what happens when this runs through it says that it has failed.

165
00:11:03,760 --> 00:11:08,710
Now we're going to find out why that is and that's because our switch must be exhaustive.

166
00:11:08,710 --> 00:11:13,950
A barcode can be UPC or QR code so we need to give it an option to do something.

167
00:11:13,960 --> 00:11:19,690
If a QR code gets passed in otherwise the app could crash so it's helping us to be safe actually which

168
00:11:19,690 --> 00:11:21,040
is pretty cool.

169
00:11:21,040 --> 00:11:27,190
Also at the end of a case for a switch we need to put a colon so it knows that that's the end of that

170
00:11:27,190 --> 00:11:27,940
case.

171
00:11:28,050 --> 00:11:32,000
OK let's go ahead and let's do that now for a QR code.

172
00:11:32,030 --> 00:11:38,980
So case let QR code and what we're going to do is we simply just have a product code.

173
00:11:39,280 --> 00:11:39,650
OK.

174
00:11:39,700 --> 00:11:44,590
Because for a QR code we're only passing in one value which is a string.

175
00:11:44,920 --> 00:11:53,380
So for the case product code we're going to go ahead and just print QR code and we're going to just

176
00:11:53,380 --> 00:11:56,630
give it the product like so.

177
00:11:57,040 --> 00:11:57,620
All right.

178
00:11:57,790 --> 00:12:00,300
So now our switch is exhaustive.

179
00:12:00,400 --> 00:12:05,050
It's giving us an error though let's figure out what the problem is.

180
00:12:05,110 --> 00:12:10,190
We have said case L'Etat UPC number system manufacturer product code check.

181
00:12:10,360 --> 00:12:10,830
Oh OK.

182
00:12:10,840 --> 00:12:12,650
So the colon is in the wrong place my bet.

183
00:12:12,670 --> 00:12:14,670
I put it at the end of the print statement.

184
00:12:14,730 --> 00:12:15,120
Cool.

185
00:12:15,130 --> 00:12:15,880
There we go.

186
00:12:15,880 --> 00:12:17,450
That looks wonderful.

187
00:12:17,500 --> 00:12:24,880
So do some cleanup here and now you can see it prints because it is a UPC barcode printed out 8 4 8

188
00:12:24,880 --> 00:12:27,160
5 9 9 5 1 2 2 6 and 3.

189
00:12:27,160 --> 00:12:29,980
So now we have access to those values.

190
00:12:30,100 --> 00:12:30,810
Really cool.

191
00:12:31,060 --> 00:12:36,690
But what happens if I wanted to change the product barcode into a QR code.

192
00:12:36,820 --> 00:12:44,480
We could do that by just setting product barcode equals dot QR code and we can give it a string value.

193
00:12:44,500 --> 00:12:48,790
So for that I'll just type a bunch of random characters and now that it's a QR code watch what happens

194
00:12:48,790 --> 00:12:50,360
when it goes through the switch statement.

195
00:12:50,590 --> 00:12:52,610
It prints it out as a QR code.

196
00:12:52,630 --> 00:12:53,350
That's really cool.

197
00:12:53,350 --> 00:12:59,140
So as you can see enumerations are really helpful and they can be used for a lot of different things

198
00:12:59,860 --> 00:13:01,690
beyond dissociated values.

199
00:13:01,690 --> 00:13:07,110
We can do lots of different things like we can set explicit values and types for our enumerations.

200
00:13:07,120 --> 00:13:08,490
So I'm gonna show you that now.

201
00:13:08,680 --> 00:13:14,100
Let me pull this back open in full screen here and let's give us some space so we can actually see.

202
00:13:14,660 --> 00:13:15,530
There we go.

203
00:13:15,820 --> 00:13:24,270
So I'm going to create a numeration for Jet II masters and let's do that by typing ENM jet.

204
00:13:24,360 --> 00:13:30,430
M. Of course we're using the kind of conventions that you would for declaring a class with capital letters

205
00:13:30,430 --> 00:13:31,340
at the beginning.

206
00:13:31,510 --> 00:13:36,100
And what we're going to do is we're going to set up a few different cases so some jet masters that I

207
00:13:36,100 --> 00:13:43,440
can remember right now are let's do case yota case Mace Windu.

208
00:13:43,930 --> 00:13:50,300
How about Kwai Gunjan upstairs to end their case.

209
00:13:50,350 --> 00:13:52,900
Obi Wan Kenobi.

210
00:13:52,930 --> 00:13:53,780
Who else.

211
00:13:53,830 --> 00:13:56,320
I'm Luke Skywalker.

212
00:13:56,350 --> 00:13:58,560
I guess he could be in there.

213
00:13:58,630 --> 00:14:06,310
So as you can see there are a bunch of different masters in our enumeration and if we were to print

214
00:14:06,340 --> 00:14:12,720
this out watch what happens if we print master datt Yoda.

215
00:14:12,760 --> 00:14:15,690
Watch what Prince out.

216
00:14:15,750 --> 00:14:19,210
So you can see Yoda with a lowercase why prints out.

217
00:14:19,380 --> 00:14:23,390
And that's because since this is just text we haven't really told anything else.

218
00:14:23,460 --> 00:14:28,590
It's actually inferring that it is a string which is cool it lets us print it out and that's really

219
00:14:28,590 --> 00:14:29,340
helpful.

220
00:14:29,460 --> 00:14:33,200
But what if I wanted to include Yoda's name in an app.

221
00:14:33,210 --> 00:14:37,150
Of course since it's a proper noun it should have a capital letter at the beginning.

222
00:14:37,260 --> 00:14:40,440
I can do that by setting an explicit type for this enumeration.

223
00:14:40,590 --> 00:14:47,100
So to do that you can actually do it just like you would inherit in a class by typing a colon and adding

224
00:14:47,100 --> 00:14:47,980
string.

225
00:14:48,330 --> 00:14:52,050
So now each of these cases are explicitly a string.

226
00:14:52,050 --> 00:14:57,720
But what we can do is we can set a value for these cases and we can access it by pulling out the raw

227
00:14:57,720 --> 00:14:58,480
value.

228
00:14:58,500 --> 00:15:06,960
So just like you would with a constant or variable go ahead and type Yoda K with a capital letter go

229
00:15:06,960 --> 00:15:10,570
ahead and type Mace Windu.

230
00:15:10,880 --> 00:15:13,560
Go ahead and try whoopsies.

231
00:15:13,560 --> 00:15:14,210
Come on.

232
00:15:14,430 --> 00:15:20,130
Go ahead and type q a gun.

233
00:15:20,180 --> 00:15:22,000
Gin.

234
00:15:22,130 --> 00:15:22,620
Go ahead.

235
00:15:22,630 --> 00:15:23,230
Hi.

236
00:15:23,280 --> 00:15:26,290
Obi Wan Kenobi.

237
00:15:26,970 --> 00:15:32,770
And go ahead and type Luke Skywalker without the capital K.

238
00:15:33,120 --> 00:15:33,720
Ok cool.

239
00:15:33,720 --> 00:15:39,480
So as you can see these all now have an explicit string type which is really cool but you probably noticed

240
00:15:39,480 --> 00:15:45,030
that Yoda is still printing out lowercase which is the value for the case but not the explicit value

241
00:15:45,030 --> 00:15:49,930
we've set to access that all we need to do is pull out the raw value.

242
00:15:49,950 --> 00:15:50,550
Watch what happens.

243
00:15:50,550 --> 00:15:53,490
Now when I print it prints out the capital Y Yoda.

244
00:15:53,490 --> 00:16:01,260
If I were to change that to master yoda you can see it prints out Master Yoda the explicit string value

245
00:16:01,260 --> 00:16:03,480
that we've set which is super cool.

246
00:16:03,480 --> 00:16:05,610
So you can do this for all kinds of things.

247
00:16:05,610 --> 00:16:10,910
Integers doubles even your own custom types or classes which is really neat.

248
00:16:11,040 --> 00:16:16,840
And so we just printed out the raw value for the explicit type that we've set for this enumeration.

249
00:16:17,070 --> 00:16:19,880
But you know what this is not really super practical.

250
00:16:19,900 --> 00:16:22,350
And these are all just sort of toy examples.

251
00:16:22,380 --> 00:16:28,530
I want to show you now how you could manage the state of a switch or a button by basically just creating

252
00:16:28,530 --> 00:16:33,440
a simple enumeration to hold the status of a switch on or off.

253
00:16:33,450 --> 00:16:36,210
It's simple but it's something that you could do in an app.

254
00:16:36,480 --> 00:16:40,900
So go ahead and type in them switch status.

255
00:16:41,130 --> 00:16:48,330
OK and we're going to set two cases on and off which makes sense so go ahead and type case on IN CASE

256
00:16:48,600 --> 00:16:49,920
off.

257
00:16:49,920 --> 00:16:54,930
There's two options right now what we're going to do is we're going to go ahead and create a variable

258
00:16:55,080 --> 00:17:01,740
that's going to hold the value for our or switch status and we're going to set it to be equal to off

259
00:17:01,770 --> 00:17:04,200
initially and then toggle it using a function.

260
00:17:04,200 --> 00:17:05,480
So let's do that now.

261
00:17:05,670 --> 00:17:08,550
Go ahead and type var switch status.

262
00:17:08,970 --> 00:17:12,920
Let's make it explicitly of type switch.

263
00:17:12,990 --> 00:17:15,480
Oh my gosh let's make it explode.

264
00:17:15,780 --> 00:17:20,720
Explicitly switch status and let's set it to be dot.

265
00:17:21,090 --> 00:17:23,860
And as you can see we have our two options here that pop up.

266
00:17:23,880 --> 00:17:27,250
We'll set it to be off from the beginning already.

267
00:17:27,350 --> 00:17:33,990
Now we're going to write a function that is going to invert the value of our switch status if if it's

268
00:17:34,080 --> 00:17:37,950
off we'll run it to the function and it will return on if it's on.

269
00:17:37,960 --> 00:17:40,160
We're going to return off super simple.

270
00:17:40,170 --> 00:17:41,880
So go ahead and write func.

271
00:17:42,210 --> 00:17:44,430
Whoops flip switch.

272
00:17:44,910 --> 00:17:45,530
OK.

273
00:17:45,570 --> 00:17:52,380
We're going to pass in a status of type switch status and we're going to return a switch status as well.

274
00:17:52,710 --> 00:17:53,350
OK.

275
00:17:53,550 --> 00:18:03,920
So if we pass in a status of off if status is equal to off we're going to go ahead and return on.

276
00:18:03,990 --> 00:18:04,230
Right.

277
00:18:04,230 --> 00:18:09,930
That makes sense if it's off we're going to turn it on else meaning if we pass it on we're going to

278
00:18:09,940 --> 00:18:13,040
return off just like that.

279
00:18:13,430 --> 00:18:13,710
OK.

280
00:18:13,740 --> 00:18:14,400
Really cool.

281
00:18:14,400 --> 00:18:15,520
Super simple.

282
00:18:15,600 --> 00:18:20,220
So we have turned on or off depending on what status we get passed in.

283
00:18:20,220 --> 00:18:26,010
Now let's go ahead remember that our switch status is currently off and what we're going to do is we're

284
00:18:26,010 --> 00:18:31,020
going to go ahead and call flip switch which is our function and we're going to show how the status

285
00:18:31,020 --> 00:18:33,080
of our switch is going to be flipped.

286
00:18:33,090 --> 00:18:34,510
Remember it's off now.

287
00:18:34,650 --> 00:18:38,820
And if I pass in switch status whips the one with the lower case s.

288
00:18:38,850 --> 00:18:42,480
Watch what happens when it prints out in the function over here.

289
00:18:42,480 --> 00:18:44,800
Now it's on really cool.

290
00:18:45,210 --> 00:18:52,740
If I wanted to set our switch status to be equal to on and then if I pass it into our function now watch

291
00:18:52,740 --> 00:18:59,100
what happens let's pass in switch status and it's on remember I said it on watch what happens when I

292
00:18:59,100 --> 00:19:01,250
flip it it sets it to off.

293
00:19:01,260 --> 00:19:08,310
So we're using an enumeration to handle on these related values and we can use enumerations to do all

294
00:19:08,310 --> 00:19:09,490
kinds of cool things.

295
00:19:09,510 --> 00:19:11,180
You can set associated values.

296
00:19:11,190 --> 00:19:18,660
You can set explicit types and raw values for those explicit type you can use tunnels and pass in those

297
00:19:18,750 --> 00:19:21,170
values to your associated types.

298
00:19:21,210 --> 00:19:26,160
You can do all kinds of really really cool stuff and there's much more if you dig into the Apple documentation

299
00:19:26,460 --> 00:19:28,140
on a numeration you can learn much more.

300
00:19:28,140 --> 00:19:32,400
But this is just kind of to cover the basics of enumerations and all they can do to help you.

301
00:19:32,400 --> 00:19:34,860
So let's go ahead and let's move over to the next video.

302
00:19:34,860 --> 00:19:36,500
This is Calleigh with slopes.

303
00:19:36,510 --> 00:19:36,910
Scott.

