-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathContents.swift
40 lines (32 loc) · 1.14 KB
/
Contents.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import UIKit
// App Exercise - Swimming Workouts
struct SwimmingWorkout {
static var freestyleWorkouts: [SwimmingWorkout] = []
static var butterflyWorkouts: [SwimmingWorkout] = []
static var backstrokeWorkouts: [SwimmingWorkout] = []
static var breaststrokeWorkouts: [SwimmingWorkout] = []
enum Stroke {
case freestyle, butterfly, backstroke, breaststroke
}
var distance: Double
var time: Double
var stroke: Stroke
func save() {
switch stroke {
case .backstroke:
SwimmingWorkout.backstrokeWorkouts.append(self)
case .breaststroke:
SwimmingWorkout.breaststrokeWorkouts.append(self)
case .butterfly:
SwimmingWorkout.butterflyWorkouts.append(self)
case .freestyle:
SwimmingWorkout.freestyleWorkouts.append(self)
}
}
}
var workoutOne = SwimmingWorkout(distance: 10.0, time: 2.4, stroke: .backstroke)
var workoutTwo = SwimmingWorkout(distance: 32.2, time: 87.2, stroke: .breaststroke)
workoutOne.save()
workoutTwo.save()
print(SwimmingWorkout.backstrokeWorkouts)
print(SwimmingWorkout.breaststrokeWorkouts)