Declaring an enumeration

To declare an enumeration, you list out all the possible member values as case

clauses:

enum Month { case january case february case march case april case may

case june case july case august

case september case october case november case december

}

This code creates a new enumeration called Month with 12 possible member values. The commonly accepted best practice is to start each member value with a lower case first letter, just like a property.

You can simplify the code a bit by collapsing the case clauses down to one line, with each value separated by a comma:

enum Month {

case january, february, march, april, may, june, july, august, september, october, november, december

}

That looks snazzy and simple. So far, so good.

results matching ""

    No results matching ""