Chapter 15. Structs and Classes

You learned that an enum can be a powerful way to model custom data, such as the state of a light bulb. Using associated values, you were able to attach some arbitrary data to your enum cases, which made them even more flexible for data modeling. But while enums are great for representing a singular value with some associated contextual data, they are not designed for modeling large or complex systems.

For that, you use a structure (commonly just called a struct) or a class. These types are syntactically similar, which is why we will introduce them together. Over the next several chapters, you will learn about the important similarities, differences, and uses for these types.

For the next few chapters, you will ...

Get Swift Programming: The Big Nerd Ranch Guide, 3rd Edition 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.