8.10 Summary
In this chapter, you learned about structs in Swift, which can be considered data container templates. Typically, structs are used to store and represent the properties of an entity. Beyond simple values, structs can also contain computed properties and functions, which increases their flexibility. Structs even offer encapsulation, via which their components can be marked as private to limit the access of callers. Finally, generics can be applied to structs too.
When all those features are brought together, the borders between structs and classes get blurry—and they certainly overlap in many cases. However, they have significant differences and are typically used for different purposes. As you learn about classes in the next ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access