Search code examples
swiftperformancefinal

Swift Final Classes and Functions


This may seem like a trivial question about performance, but in Swift, if you declare a class as final is it necessary to also declare all of its methods as final or is that just a superfluous redundancy? I just want to make sure my concrete classes run as final to maximize security and performance in my app. Thanks for any tips, wisdom, or knowledge in advance!


Solution

  • Swift if you declare class as final is it necessary to also declare all of its methods as final or is that just a superfluous redundancy

    Yes, it's redundant. If the class is final, all its members are final by implication. You are getting the efficiency of avoiding dynamic dispatch, and what's what you want to do.