Listing Possibilities with Enumerations

Structures are familiar to old C programmers, and they were available in Objective-C but were so limited that they were often ignored in favor of classes. Swift extensions tilt the balance back toward structs, as it does with another old C type: enumerations. The enum is a type that enumerates all its possible values. Its nice for times when you want to know there are a small number of valid values for something, like the suits of playing cards, positions in a team sport, and so forth.

Start a new playground called EnumsPlayground, and delete the "Hello playground" line. We’re going to use this playground to rethink our IOSDevice.

So far, whether class or struct, we’ve assumed our IOSDevice is a touchscreen ...

Get iOS 9 SDK Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.