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 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.