Swift: Similarities and differences between Structures and Classes

Swift provides as with two basic constructs: Structures and Classes which are the building blocks of our code. Structures are value type. Classes are reference types.Structures and classes have the following similar characteristics:

  • We can define methods
  • We can define properties
  • We can define subscripts
  • We can define initializers
  • We can extend them to perform additional functions
  • We can make themĀ conform to any protocols as needed

In addition to the above aspects, Classes also have the following characteristics:

  • We can define deinitializers
  • We can perform type casting
  • We can inherit properties and methods from another class(Inheritance)
  • We can perform reference counting

 

Leave a Reply