Reputation: 1937
What are the implications of doing the following:
protocol A {
func f()
}
extension A {
final f() {}
}
I'm looking to understand what putting final
in the extension over here does when compared to not putting it. I know what final
does, I'm looking to understand overriding behaviour for classes implementing/not implementing f
and their subclasses.
Upvotes: 4
Views: 1732
Reputation: 3807
You can no longer mark extension funcs as final.
https://bugs.swift.org/browse/SR-1762
Upvotes: 3
Reputation: 8771
For Swift 2.0: Protocol Extensions
Referring to this question of Inheritance, final keyword would not allow to override the (final) method defined in Extension, when it's Sub-classed.
For Swift 1.2: This might be useful in context of Extensions Extensions can add new functionality to a type, but they cannot override existing functionality
Few things to look in context of Extensions, while decide on architecture of applications:
On final keyword, this is my take it has no impact on Extensions methods as compared to classes(Inheritance). Please correct me if I'm wrong here. Demo links:
Upvotes: 1