O'Reilly logo

Learn Swift on the Mac: For OS X and iOS by Waqar Malik

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter    9

Classes and Structures

In Chapter 4 you learned about object-oriented programming (OOP), and how an object can be represented in Swift as a class, a structure, or an enumeration type.

Unlike in other languages, in Swift classes and structures are very similar, with only few features that separate them. So as I describe and discuss the functionality of objects, this applies to both classes and structures. I’ll point out where they differ.

Commonality

Here are some of the things 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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required