Classes
In the following example of creating a class, notice that it looks just like a struct but with the word class
:
class FirstClass { // class implementation goes here}
You create a class exactly the same way you create a struct, but instead of using the word struct
, you use the word class
. Adding properties to a class is very similar. For example, the following Car
class has properties for the make, model, and year (and you will define a default value for each property):
class Car { let make = "Ford" let model = "Taurus" let year = 2014}
In this example, there are three immutable properties of the Car
class. Remember that when you make a struct, you are able to leave these properties blank. If you ...
Get Learning Swift™ Programming now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.