Looking Ahead: What Is the Real Difference?

In this chapter, the biggest difference that you have encountered between classes and structs is that classes support inheritance and structs do not. That alone is not a compelling reason to have both structs and classes in the language, especially since the final keyword can be used to prevent a class from being subclassed where necessary.

The underlying difference between structs and classes is a bit more subtle, but it has crucial implications for how they are used. Here is a sneak peek at a feature of structs and classes that you will explore in much greater depth later in this book.

When you have a struct or enum variable, all the memory the instance needs to store its content is inside ...

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.