9.2. Classes
At first glance, a class looks the same as a struct. However, there are a few major differences between them.
We will discuss classes using the differences they have.
An example of a class is as follows:
class Vehicle{
var type:String
}If you just write the above block of code, you'll get an error:

So, it is not like a struct where you do not need to have an initializer method. You must have your own initializer to be able to create an instance of a class. This is the first difference between a** struct and a class.**
Now let's define our init() method and create a variable:
Last updated
Was this helpful?