All the above answers explain how to do it, but not why.
When thinking about protocols, you have to make a mental switch - protocols are not structures. When you define protocol conformance, you only give a set of required things that a conforming type has to pack. Give or take how that type is going to implement them.
protocol InstrumentForProfessional {
var title: String {get}
}
protocol Pen: InstrumentForProfessional {
var title: String {get}
var color: UIColor {get}
}
protocol Watch: InstrumentForProffesional {}
protocol Tiger {} // Not an instrument
A Pen doesn't conform to InstrumentForProfessional. It is InstrumentForProfessional. Another example would be having Instrument protocol and having a StringInstrument. You know, StringInstrument doesn't conform to Instrument; it is an Instrument.
What I think you are looking for is default implementations of certain fields. Consider this example; every MovingObject should tell its maximum speed. Is Car a moving object? Yes, it is. Should it conform to MovingObject? NO!
protocol MovingObject {
/// Top speed a vehicle can reach in km/h.
var topSpeedKMH: Double { get }
}
protocol Car: MovingObject {
/// Horsepower of a car.
var hp: Double { get }
var weight: Double { get }
// Note that topSpeed is also required,
// but since we specified it in MovingObject we don't have
// to rewrite it here.
// var topSpeedKMH: Double { get }
}
But we know that we can calculate top speed from horsepower and weight. That's why we create a default implementation.
extension Car {
var topSpeedKMH: Double {
hp * weight
}
}
Every Car now can conform to a MovingVehicle "out-of-the-box"; yet, it could still provide its own implementation for every given field.