Last active
December 8, 2015 16:04
-
-
Save eofster/e41f3683f009b94121ec to your computer and use it in GitHub Desktop.
GPS track summary presenter
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
| 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