Overriding
Swift permits a class or object to replace the implementation of a behavior/property that it has inherited. This process is called overriding. The override keyword is used to specify overridden methods in subclasses.
We can override an inherited instance or class property to provide our own custom/computed getters and setters or add property observers to enable the overriding property to observe when the underlying property value changes.
We can mark a property or behavior as final to prevent overriding it in subclasses.
Overriding brings a complication that needs to be handled. We need to ensure which version of the behavior/property an instance of the subclass should use: the one that is part of its own class (self) or the one ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access