Last active
January 29, 2018 22:07
-
-
Save igavrysh/c14eaf624839016d15af00474ca13b0c to your computer and use it in GitHub Desktop.
This file contains 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
struct SwimmingWorkout { | |
var distance: Double | |
var time: Double | |
var stroke: Stroke | |
static var breaststrokeWorkouts: [SwimmingWorkout] = [] | |
static var freestyleWorkouts: [SwimmingWorkout] = [] | |
static var butterflyWorkouts: [SwimmingWorkout] = [] | |
static var backstrokeWorkouts: [SwimmingWorkout] = [] | |
enum Stroke { | |
case freestyle, backstroke, breaststroke, butterfly | |
} | |
func save() { | |
switch self.stroke { | |
case .freestyle: | |
SwimmingWorkout.freestyleWorkouts.append(self) | |
case .butterfly: | |
SwimmingWorkout.butterflyWorkouts.append(self) | |
case .breaststroke: | |
SwimmingWorkout.breaststrokeWorkouts.append(self) | |
case .backstroke: | |
SwimmingWorkout.backstrokeWorkouts.append(self) | |
} | |
} | |
} | |
let backstroke1 = SwimmingWorkout(distance: 7.8, time: 4.5, stroke: .backstroke) | |
backstroke1.save() | |
print("Add one backstroke exercise: " | |
+ String(describing: SwimmingWorkout.backstrokeWorkouts) + "\n\n") | |
let backstroke2 = SwimmingWorkout(distance: 14, time: 26.2, stroke: .backstroke) | |
backstroke2.save() | |
print("Add second backstroke exercise: " | |
+ String(describing: SwimmingWorkout.backstrokeWorkouts)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment