December 2015
Intermediate to advanced
400 pages
13h 3m
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 ExerciseType to inherit from CustomStringConvertible, meaning it also requires the description property.
Listing 23.9 Making ExerciseType inherit from CustomStringConvertible
protocol ExerciseType: CustomStringConvertible {
var name: String { get }
var caloriesBurned: Double { get }
var minutes: Double { get }
}
...
Your playground ...
Read now
Unlock full access