Read Source: Official Swift2.0 Tutorial Chinese version
Today we learned the enumeration types of swift, and the following are the contents and summaries:
Use enum to create an enumeration. Like classes, enumerations can also contain methods.
enum rank: int { case ace =1 case two, three, four, five, six, seven, eight, nine, ten case Jack, queen, king func simpledescription () -> String { switch self { case . ace: return "Ace"          CASE . jack: return "Jack"          CASE  queen: return "Queen"          CASE . king: return "King" default: return String (Self.rawvalue) } }}let ace = rank.aceletacerawvalue = Ace.rawvalue
Practice:
Write a function that compares two Rank instances with the original values.
In the example above, the type of the enum original value is Int, so you only have to set the original value of the first case. The remaining raw values are assigned in order. You can also use a string or a floating-point number as the original value of the enumeration. Use the RawValue property to access the original value of an enumeration member.
Use init? (RawValue:) The constructor method transforms between the original value and the enumeration.
If Let Convertedrank = Rank (rawvalue:3) {Let threedescription = Convertedrank.simpledescription ()}
If you do not use the original value, you can not set it.
Enum Suit {case spades, Hearts, diamonds,clubs func simpledescription ()-String {switch Self { Case. Spades:return "Spades" case. Hearts:return "Hearts" case. Diamonds:return "Diamonds" case. Clubs:return "Clubs"}}}let hearts = Suit.heartslet heartsdescription = hearts.simpledescription ()
Note that there are two ways to refer to a Hearts member: When assigning a value to a Hearts constant, because it does not explicitly specify a type, Suit.hearts is represented by its full name. In switch, because the type of self is known, enumeration members can use abbreviations such as. Hearts to reference.
Swift Syntax 01-enum type