10.3 Declaring a Swift Class
Before an instance can be created, we first need to define the class ‘blueprint’ for the instance. In this chapter we will create a bank account class to demonstrate the basic concepts of Swift object-oriented programming.
In declaring a new Swift class we specify an optional parent class from which the new class is derived and also define the properties and methods that the class will contain. The basic syntax for a new class is as follows:
class NewClassName: ParentClass {
// Properties
// Instance Methods
// Type methods
}
The Properties section of the declaration defines the variables and constants that are to be contained within the class. These are declared in the same way that any other variable or constant would be declared in Swift.
The Instance methods and Type methods sections define the methods that are available to be called...