“Final” keyword — Swift 5 (iOS)

Understanding the Final keyword and decoding the mystery.

Source: https://unsplash.com/@johnschno | Edited: Self

Implications of using final

Prevent Inheritance and Overriding

Compiler error occurs when we try to inherit a final class
A User class. We want to control the behavior of generateKey() and getChars(:). So, it is declared final to restrict any changes.
A Consumer class inherited from the User class. As shown a compile-time error occurs when we try to override a final member.

Enhance Runtime Performance

A class User is defined and is instantiated to create an object, user.
A class User is defined and is instantiated to create an object, user.

iOS Developer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store