[MUSIC] Now that we've looked at how to create basic enumerations, let's look at how we can create enumeration types that have a raw-value type. This is especially helpful when we're working with database values. We can store an object's status or some kind of object type or other discrete list of cases for an object as a property of that object in the database. For example, our planets, if they were in a database, might have a column called order that would tell us the order they appear in terms of distance from the planet's home star. So Mercury, for example, would have order zero, Venus one, Earth two, etc. Now, we can define cases in an enum similar to how we just saw. But attach an Int raw-value type to it. So now, when we get database value when we see the order zero we can immediately turn that into Mercury using the enum. All right, we can also have other types of raw-value types for our enum. We can use all the basic Swift and numeric types and the string type. Let's take a look at how we can do this in the playground. Look for how we specify value types for enums using a colon, just like we do for specifying the types of any other variable or constant or function argument. We always specify the type using a colon. So that shouldn't be new, and I wanted to make a point that enums with the raw-value type of Int can be listed out comma delimited on one line of code, instead of writing the cases on separate lines. That's also just fine. But this way we can get the Int values automatically associated with our different cases in the enums, and they'll be consecutive numbers. So take a look at that in the playground. All right, so let's take a look at how we can actually use those enums with the raw-value types. So here again we have another enum. Just because this is on the same playground, I had to call it something different. So I've called this enum MilkyWayPlanet. And that actually kind of makes sense because if I was trying to model out all of the planets in the galaxy, or the whole universe, or something like that, this could become a very long enum if I just call it planet. So it'll make more sense, to break those up into multiple different enums. In my application, theoretical application, I may only be interested with a few different solar systems, so it'd be manageable to have a MilkyWayPlanet and some other galaxy planet enum so that these list of cases don't get too long and the code becomes difficult to read. Okay, notice here how we have declared MilkyWayPlanet, that enum, to have an Int value type. So again, keyword enum. The name of the enum, MilkyWayplanet. And then the colon, and then raw-value type of Int. So that means now that we can either refer to all of these cases as MilkyWayPlanet.Mercury, MilkyWayPlanet.Venus, etc. We can also, as we previously saw, just refer to them as .Mercury, .Venus, etc., if we have explicitly typed things so that Swift can infer the type of enum. And we can also refer to these by raw-value type. So we'll have the Int value type of zero. Venus will have the Int value type of one and so on. And we'll just down in the order they appear in the enum. All right, notice here that the compiler reminds us that stored properties cannot be set on an enum type. Here we are inside of our enum's body, right? Inside of these curly braces. And I've commented this line of code out. And if I uncomment it, notice that I immediately get a warning that says, enumss may not contain stored properties. We'll talk more about properties later, but I just wanted to take a point to point that out now. So I'll comment that back out to get rid of the error. We can also pick computed properties into an enum, so we will talk more about properties later, but let's not go over that for right now. I'm going to also show you how you can list out enums in one line of code like I mentioned earlier. So here I have an another enum called CelestialBodyTaxon which we'll look at how we use that in a later presentation. But this is another enum with an Int raw-value type associated with it. So here have my list of cases. And notice that I just read the keyword case one time and then I have the names of all the cases separated by commas. The first case I assign the Int value of zero to. I could also have started at one or something. But because arrays are zero indexed, and this is, even though it's an enum and not an array, so it's not really a list. We are still, when we write the code out, we still type it as a list. So just to keep everything zero indexed, and not have to remember does this enum start at one or does it start on zero, just start out on zero, if that makes sense, for your implementation. And in most cases it will. So I've defined the case of Unknown equal zero and then I put comma, all of the rest of the cases, Star, comma, Planet, comma, Moon. So these are all the different categories of celestial bodies that I'll allow into my solar system. Notice here that I said Unknown equals zero, so we know that its Int value for the case Unknown will be zero. But what about the rest of the cases in the list here. We'll they all just go ahead and get the next number after the first value here. So Star will have the Int value of one, Planet will have the Int value of 2, Moon will have the Int value of three, etc. And I can just keep on adding cases by saying comma the next type. So, if wanted to add a category for Pluto, for example, I can say there's now a new type called the DwarfPlanet that my enum supports. And this is a very good way to keep your code manageable using enums. Instead of adding DwarfPlanet in the middle of this already existing list, add new enums to the end of the list. That way you don't go have to go and change all your code wherever your inspecting the Int value of that enum or raw-value of that enum. I can just say say now instead of having to worry about if the type equals two, which used to be Planet and if I moved Dwarf Planet before Planet, now I'd have to bump everything in my code down by one number everywhere in my code, versus if I add it to the end of the list as a new case. Now it just gets zero, one, two, three, four, and I can say if its raw-value equals four, do this without having to change any other code. [MUSIC]