Skip to main content

Swift - Structure and Classes

Structures and Classes:

How are structures different ?

  1. No inheritance. 
  2. No type casting to check at runtime. 
  3. No reference counting. No multiple references. 
  4. No deinitializers. 

  1. Structures are value types. When you assign instance of a struct to another variable, the entire structure is COPIED and not REFERENCED.
  2. Classes instead are REFERENCE types, pointing to the same instance. 

  1. === operator is to know if two variables / constants refer to the same instance. 
  2. == means they are equal in some value. It is your responsibility to implement == and != in your class.