O'Reilly logo

Swift Quick Syntax Reference by Matthew Campbell

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

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