Skip to content

Commit 2807337

Browse files
committed
Reformat code for readability
1 parent b337d82 commit 2807337

File tree

1 file changed

+42
-37
lines changed

1 file changed

+42
-37
lines changed

Weight WatchKit Extension/SuccessInterfaceController.swift

Lines changed: 42 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -16,49 +16,54 @@ class SuccessInterfaceController: WKInterfaceController {
1616
@IBOutlet weak var bmiCategoryLabel: WKInterfaceLabel!
1717
@IBOutlet weak var motivationLabel: WKInterfaceLabel!
1818

19+
let defaultString = "---"
20+
var resultParameters: ResultsParameters?
21+
1922
override func awake(withContext context: Any?) {
2023
super.awake(withContext: context)
21-
let defaultString = "---"
2224

2325
if let parameters = context as? ResultsParameters {
24-
if let weightKG = parameters.weightKG {
25-
let weightLabelText = String.localizedStringWithFormat(LocalizedStrings.weightLabel, weightKG)
26-
weightLabel.setText(weightLabelText)
27-
} else {
28-
weightLabel.setText(defaultString)
29-
}
30-
31-
if let bmi = parameters.bmi {
32-
let bmiLabelText = String.localizedStringWithFormat("%.1f", bmi)
33-
bmiLabel.setText(bmiLabelText)
34-
} else {
35-
bmiLabel.setText(defaultString)
36-
}
37-
38-
if let bmiCategory = parameters.bmiCategroy {
39-
switch bmiCategory {
40-
case .Underweight:
41-
bmiCategoryLabel.setText(LocalizedStrings.underweightBmi)
42-
case .Normal:
43-
bmiCategoryLabel.setText(LocalizedStrings.normalBmi)
44-
case .Overweight:
45-
bmiCategoryLabel.setText(LocalizedStrings.overweightBmi)
46-
case .Obese:
47-
bmiCategoryLabel.setText(LocalizedStrings.obeseBmi)
48-
}
49-
} else {
50-
bmiCategoryLabel.setText(defaultString)
51-
}
52-
53-
if let weight = parameters.weight, let oldWeight = parameters.oldWeight {
54-
let difference = ((weight - oldWeight) / 100).rounded() / 10
55-
let differenceLabelText = String.localizedStringWithFormat(LocalizedStrings.weightDifference, difference)
56-
differenceLabel.setText(differenceLabelText)
57-
} else {
58-
differenceLabel.setText(defaultString)
59-
}
26+
self.resultParameters = parameters
27+
updateDisplay(parameters)
6028
} else {
6129
print("Error recieving parameters")
6230
}
6331
}
32+
33+
func updateDisplay(_ resultParameters: ResultsParameters) {
34+
// Set all parameters to default in advance.
35+
weightLabel.setText(defaultString)
36+
bmiLabel.setText(defaultString)
37+
bmiCategoryLabel.setText(defaultString)
38+
differenceLabel.setText(defaultString)
39+
40+
if let weightKG = resultParameters.weightKG {
41+
let weightLabelText = String.localizedStringWithFormat(LocalizedStrings.weightLabel, weightKG)
42+
weightLabel.setText(weightLabelText)
43+
}
44+
45+
if let bmi = resultParameters.bmi {
46+
let bmiLabelText = String(format: "%.1f", bmi)
47+
bmiLabel.setText(bmiLabelText)
48+
}
49+
50+
if let bmiCategory = resultParameters.bmiCategroy {
51+
switch bmiCategory {
52+
case .Underweight:
53+
bmiCategoryLabel.setText(LocalizedStrings.underweightBmi)
54+
case .Normal:
55+
bmiCategoryLabel.setText(LocalizedStrings.normalBmi)
56+
case .Overweight:
57+
bmiCategoryLabel.setText(LocalizedStrings.overweightBmi)
58+
case .Obese:
59+
bmiCategoryLabel.setText(LocalizedStrings.obeseBmi)
60+
}
61+
}
62+
63+
if let weight = resultParameters.weight, let oldWeight = resultParameters.oldWeight {
64+
let difference = ((weight - oldWeight) / 100).rounded() / 10
65+
let differenceLabelText = String.localizedStringWithFormat(LocalizedStrings.weightDifference, difference)
66+
differenceLabel.setText(differenceLabelText)
67+
}
68+
}
6469
}

0 commit comments

Comments
 (0)