Skip to content

Instantly share code, notes, and snippets.

@eofster
Created December 15, 2015 12:57
Show Gist options
  • Save eofster/db8136cd846220568311 to your computer and use it in GitHub Desktop.
Save eofster/db8136cd846220568311 to your computer and use it in GitHub Desktop.
GPS track summary presenter with track ID
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