Chapter    40

Overriding Methods and Properties

When you use inheritance with a class, you can change how the parent class methods and properties behave by overriding. When you override a method, an instance will behave differently than its parent instance even though the same method name is used as the function call.

For instance, in Chapter 39 you had two classes. The parent class name Person had a method named profile() that returned a string describing the Person instance. Employee instances also have this method, and they are identical.

Note  In the code in Listing 40-1, the code has been modified from the previous chapter to include a property for a person’s last name.

Listing 40-1. Person and Employee Classes

class Person {    var name: ...

Get Swift Quick Syntax Reference 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.