SWIFT OJECT - ORIENTED FEATURE

Learning notes about object oriented features of the Swift programming language.

Class Like Constructs In Swift

In Swift, enum, struct, class all can:

  1. have properties to keep states.

  2. have methods to perform actions.

  3. define subscript operators to let user access their properties through subscript syntax.

  4. define initializers to have a reasonable initial state.

  5. be extended to have additional behaviors beyond their default implementations.

  6. conform to protocols.

Only class can:

  1. have inheritance capability.

  2. have deinitializer.

  3. be referenced by mutiple variable or constants. the struct and enum are both value types.

Properties

stored properties

lazy properties

computed properties

shorthand setter syntax

shorthand read-only getter syntax

Initializers