Sobes.tech
Junior — Middle

How to declare a class so that it cannot be inherited?

sobes.tech AI

Answer from AI

In Swift, to prevent a class from being inherited, it is declared with the keyword final. Such a class cannot be used as a base for other classes.

Example:

final class MyClass {
    // properties and methods
}

// Attempting to inherit will cause a compile-time error
// class SubClass: MyClass {} // Error
How to declare a class so that it cannot be… - sobes.tech