SWIFT NOTES - CLASS VS STRUCT & ENUM

Differences between Swift classs and structs, enums.

The most distinct difference:

In general, the common things they have:

  1. can define properties, methods, subscipts
  2. can define initializers
  3. can be extended by extensions
  4. can confirm to protocols

Features exclusively owned by class

  1. inheritance
  2. deinitialization
  3. reference counting
  4. type casting

Features exclusively owned by structure

  1. memeber-wise initializer

Features exclusively owned by enum

  1. self assigning

When defining failable initializer:

You can use constant implicitly unwrapped optional property to satisfy rule #2 without first assign an valid initial value to it.