Skip to content

Commit 630045b

Browse files
committed
Ensure weight is positive on watch os interface
1 parent 746ee96 commit 630045b

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

Weight WatchKit Extension/EntryInterfaceController.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,8 @@ class EntryInterfaceController: WKInterfaceController, WKCrownDelegate {
228228

229229
private func changeWeight(by addedMass: Measurement<UnitMass>) {
230230
if let unwrappedWeight = localData.weight {
231-
let updatedWeight = unwrappedWeight + addedMass
231+
// Add weights together and ensure they're positive by clamping.
232+
let updatedWeight = (unwrappedWeight + addedMass).clamped(0, Double.infinity)
232233
localData.weight = updatedWeight
233234
} else {
234235
print("Unable to change weight (Reason: Weight is nil)")

0 commit comments

Comments
 (0)