How to prevent overrides in Swift?

We can prevent a method, property or subscript from being overridden by including the prefix final. If we try to override a property, method or subscript with final keyword, it will result in compile time error. We can make a entire class as final  by including the final keyword before the class definition. This will prevent any attempt for subclassing the respective class.

 

Syntax:

final var someName: String = “SomeName”

 

Leave a Reply