April 2015
Intermediate to advanced
556 pages
17h 47m
English
If you use a Vector value in string interpolation, you will not get a very pleasing result:
println("Gravity is \(gravity).") "Gravity is __lldb_expr_247.Vector."
You can improve this by conforming to the Printable protocol, which looks like this:
protocol Printable {
var description: String { get }
}
We will cover protocols in more detail in Chapter 6, but the short version is that a protocol defines a set of properties or methods. In order to conform to a protocol, your type must implement the required properties and methods.
To conform to Printable, you must implement a read-only computed property called description to return a String. Start by declaring that Vector conforms to Printable:
struct ...
Read now
Unlock full access