Swift 4 Programming Cookbook by Keith Moon

Swift 4 Programming Cookbook by Keith Moon

Author:Keith Moon
Language: eng
Format: epub
Tags: COM046000 - COMPUTERS / Operating Systems / General, COM051460 - COMPUTERS / Programming / Mobile Devices, COM051010 - COMPUTERS / Programming Languages / General
Publisher: Packt Publishing
Published: 2017-09-27T10:23:29+00:00


var start: TransportType.CollectionPoint

var end: TransportType.CollectionPoint

let method: TransportType

var distanceInKMs: Double

var durationInHours: Double

init(method: TransportType,

start: TransportType.CollectionPoint,

end: TransportType.CollectionPoint) {

self.start = start

self.end = end

self.method = method

// CoreLocation provides the distance in meters,

// so we divide by 1000 to get kilometers

distanceInKMs = end.location.distance(from: start.location) / 1000

durationInHours = distanceInKMs / method.averageSpeedInKPH

}

}

The last thing we need to do is to ensure that our TrainStation enum conforms to TransportLocation as this is now a requirement; we just need to declare conformance and add a location property:

enum TrainStation: String, TransportLocation {

case BMS = "Bromley South"

case VIC = "London Victoria"

case RAI = "Rainham (Kent)"

case BTN = "Brighton (East Sussex)"

// Full list of UK train stations codes can be found at

// http://www.nationalrail.co.uk/static/documents/content/station_codes.csv



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.