How it works...

Classes are defined with the class keyword, class names start with a capital letter by convention, and the implementation of the class is contained, or "scoped", within curly brackets:

class Person {     //...}

An object can have property values, which are contained within the object. These properties can have initial values, as countryOfResidence does in the following code, although bear in mind that constants (defined with let) cannot be changed once the initial value has been set:

class Person {    let givenName: String    let middleName: String    let familyName: String    var countryOfResidence: String = "UK"    //...}

If your class were to just have the preceding property definitions, the compiler would raise a warning, as givenName, ...

Get Swift 4 Programming Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.