Skip to content

Instantly share code, notes, and snippets.

@eofster
Last active December 8, 2015 16:04
Show Gist options
  • Select an option

  • Save eofster/e41f3683f009b94121ec to your computer and use it in GitHub Desktop.

Select an option

Save eofster/e41f3683f009b94121ec to your computer and use it in GitHub Desktop.
GPS track summary presenter
import Foundation
protocol TrackSummaryPresenterOutput {
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.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