November 2016
Intermediate to advanced
480 pages
14h 42m
English
Swift allows developers to create custom operators. This feature means that you can create your own operator to signify that one instance of the Person type has married another instance. Say, for example, you want to create a +++ function to marry one instance to another.
Create a new Person class like so:
Listing 25.11 Setting up a Person class
...
class Person {
var name: String
weak var spouse: Person?
init(name: String, spouse: Person?) {
self.name = name
self.spouse = spouse
}
}
The class has two properties: one for a name and another for a spouse. It also has an initializer that will give values to those properties. Note that the spouse property is an optional to indicate that ...
Read now
Unlock full access