
上QQ阅读APP看书,第一时间看更新
Enumeration types
In Swift, we can define simple types which have limited possible different values. These types are enumerations. We define them with the keyword enum. The following code is an example of this:
enum AnEnumeration {
// the value definitions goes here
}
Here's another code that does this:
enum GameInputDevice
case keyboard, joystick, mouse
}
The code has three different enumeration cases. All cases may appear on a single line, such as in the preceding code, or even one by one on a line.
We can meet the following notation, because Swift infers the missing part:
var input = GameInputDevice.mouse
//...
//later in the code
input = .joystick
The code bundle for the book is hosted on GitHub at https://github.com/PacktPublishing/Learn-Swift-by-Building-Applications. In case there's an update to the code, it will be updated on the existing GitHub repository.