December 2015
Intermediate to advanced
400 pages
13h 3m
English
Create a new command-line tool named CyclicalAssets. Add a new file to your project named Person.swift and insert the following definition of the Person class.
Listing 24.1 Defining the Person class (Person.swift)
import Foundation
class Person: CustomStringConvertible {
let name: String
var description: String {
return "Person(\(name))"
}
init(name: String) {
self.name = name
}
deinit {
print("\(self) is being deallocated")
}
}
The Person class has a single property that you set in its initializer. It conforms to the CustomStringConvertible protocol by implementing the description computed property. You add an implementation of deinit so you can see when a person is being deallocated – i.e., when its ...
Read now
Unlock full access