#97: When to Use final in Swift

Marking a class or member final means it cannot be subclassed or overridden.

final class ImageCache {
    func store(_ image: Data, forKey key: String) {}
}

This communicates design intent clearly: this type is not part of an inheritance hierarchy.

It can also unlock optimizations, but the main reason to use final is usually API clarity rather than raw performance.


I'm also on Twitter and GitHub.

Subscribe via RSS.