November 2016
Intermediate to advanced
480 pages
14h 42m
English
Both of the protocol extensions you have written so far add new properties or methods to protocols. You can also use protocol extensions to provide default implementations for the protocol’s own requirements.
Recall from Chapter 19 that the CustomStringConvertible protocol has a single requirement: a readable String property named description. Change Exercise to inherit from CustomStringConvertible, meaning it also requires the description property.
Listing 23.9 Making Exercise inherit from CustomStringConvertible
import Cocoa
protocol Exercise: CustomStringConvertible {
var name: String { get }
var caloriesBurned: Double { get }
var minutes: Double { get }
}
...
Your playground ...
Read now
Unlock full access