[swift-evolution] Final by default for classes and methods

Greg Parker gparker at apple.com
Tue Dec 22 17:22:13 CST 2015

> On Dec 22, 2015, at 11:31 AM, Kevin Ballard via swift-evolution <swift-evolution at swift.org> wrote:
> UIKit classes aren't subclassable because of a lack of sealed-by-default, they're subclassable because until very recently there was no way to mark classes as not being subclassable.

There are two historical ways to disallow subclassing of public classes.
1. Perform an isa check in your -init method and halt if it's not your class. Attempts to subclass will get runtime errors.
2. Mark your class's metaclass symbol as un-exported. Attempts to subclass will get link-time errors.

Both are used but neither is common.

> Whether the language has final-by-default/sealed-by-default doesn't really affect this in any way. I guarantee you that once Apple starts putting Swift code in their frameworks, every single framework class Apple releases is going to make an explicit decision about being final/sealed vs inheritable, and the language defaults won't affect that one bit.

You may be overestimating Apple's engineers. We're just developers too. Whatever the default is, it will be incorrectly left in place more often than you'd like.

Greg Parker     gparker at apple.com     Runtime Wrangler

More information about the swift-evolution mailing list