How to do it...

At the outset, it may not be clear as to what is the best structure to use for defining a transport method; indeed, there might be different structures appropriate for different methods. Therefore, we will define a transport method as a protocol that appropriate types can conform to:

protocol TransportMethod {     associatedtype CollectionPoint     var defaultCollectionPoint: CollectionPoint { get }     var averageSpeedInKPH: Double { get } } 

We define an associated generic type that we name CollectionPoint, which will represent the type of location that someone can be collected from when using this TransportMethod. By using generics, we have ultimate flexibility in how a transport method chooses to define what can serve as a collection ...

Get Swift 4 Programming Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.