Created
December 15, 2015 12:57
-
-
Save eofster/db8136cd846220568311 to your computer and use it in GitHub Desktop.
GPS track summary presenter with track ID
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol TrackSummaryPresenterOutput { | |
func setTrackID(trackID: Int) | |
func setName(name: String) | |
func setDate(date: String) | |
func setDistance(distance: String) | |
} | |
class TrackSummaryPresenter { | |
let output: TrackSummaryPresenterOutput | |
private let dateFormatter: NSDateFormatter | |
init(output: TrackSummaryPresenterOutput) { | |
self.output = output | |
dateFormatter = NSDateFormatter() | |
dateFormatter.dateStyle = .ShortStyle | |
} | |
} | |
extension TrackSummaryPresenter: TrackSummaryInteractorOutput { | |
func update(track: TrackSummary) { | |
output.setTrackID(track.trackID) | |
output.setName(track.name) | |
output.setDate(stringForTime(track.startTime)) | |
output.setDistance(stringForDistance(track.distance)) | |
} | |
private func stringForTime(time: Double) -> String { | |
return dateFormatter.stringFromDate(NSDate(timeIntervalSince1970: time)) | |
} | |
private func stringForDistance(distance: Float) -> String { | |
return "\(distance) m" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment