Prevent subclasses from overriding inherited functions in Swift
Look at the keyword final
.
According to the documentation,
You can prevent a method, property, or index from being overridden by marking it as final. Do this by writing a modifier
final
to the keywords the introduction of a method, property, or indexes (eg,final var
,final func
,final class func
andfinal subscript
).Any attempt to override a final method, property, or index in a subclass is reported as a compile-time error. Methods, properties, or indexes that you add to a class in an extension can also be marked as final in the extension definition.
You can find more information at the bottom of the Inheritance> section of the Swift Language manual (see the section "Preventing Overrides").
source to share