We recently wrote about Swift structs. In this tutorial, we’ll look at classes. Classes and structures have a lot in common, although there are some important differences. Let’s take a look at what a class is and what you use them for.
- A class is initialised as an object.
- You need to create an initialiser for your class.
- Classes can also inherit from other classes which bring to your class the abilities and properties of the other class. You can also override the default behaviour of a method of the parent class.
- Unlike structs which are passed around by value, classes are passed by reference.