Making Types Printable
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 ...
Get Cocoa Programming for OS X: The Big Nerd Ranch Guide 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.