Chapter 11
Classes and Structures
Unlike in other languages, in Swift, classes and structures are very similar, with only few features that separate them. So as we describe and discuss the functionality of objects, this applies to both classes and structures. We will point out where they differ.
Commonality
Here are some of the things that the classes and structures have in common:
- Properties to store values
- Methods to provide functionality
- Initializers
- Extensibility
- Conformance to protocols
Classes have some additional properties and capabilities that structures lack:
- Inheritance; classes can have parent classes, structures can’t.
- Deinitializers; classes have them, structures don’t.
- Reference counting; classes use reference counting to ...
Get Learn Swift 2 on the Mac, Second 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.