Which keyword is used to define methods and properties associated with the type itself, rather than instances?

iOS interview question for Intermediate practice.

Answer

static (or class for overridable methods in classes)

Explanation

The static keyword is used for type-level properties and methods in structs and enums. In classes, static is used for type-level properties and methods that cannot be overridden, while class is used for type-level methods that can be overridden by subclasses. The keywords instance, shared, and global are not used for this purpose in Swift.

Related Questions