Types in Swift

Swift types can be arranged into three basic groups: structures, classes, and enumerations. There are other types that fall outside of these three, such as closures, but these are the building blocks of Swift. All three can have

  • properties: values associated with a type

  • initializers: similar to a function, code that initializes an instance of a type

  • instance methods: functions specific to a type that can be called on an instance of that type

  • class or static methods: functions specific to a type that can be called on the type itself

Figure 2.1  Swift building blocks

Swift building blocks

Swift’s structures and ...

Get Cocoa Programming for OS X: The Big Nerd Ranch Guide 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.