generated from netreconlab/CareKitSample-ParseCareKit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCustomCardViewModel.swift
62 lines (54 loc) · 1.44 KB
/
CustomCardViewModel.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//
// CustomCardViewModel.swift
// OCKSample
//
// Created by Corey Baker on 4/25/23.
// Copyright © 2023 Network Reconnaissance Lab. All rights reserved.
//
import CareKit
import CareKitStore
import Foundation
class CustomCardViewModel: CardViewModel {
@Published var currentButton: ButtonOption = .isZero
@Published var value2: OCKOutcomeValue?
let amountFormatter: NumberFormatter = {
let formatter = NumberFormatter()
formatter.zeroSymbol = ""
return formatter
}()
/// This value can be used directly in Text() views.
var goalCaloriesAsInt: Int {
get {
guard let intValue = value2?.integerValue else {
return 0
}
return intValue
}
set {
value2 = OCKOutcomeValue(newValue)
}
}
var userCaloriesAsInt: Int {
get {
guard let intValue = value?.integerValue else {
return 0
}
return intValue
}
set {
value = OCKOutcomeValue(newValue)
}
}
func compareCalories() async {
if goalCaloriesAsInt == 0 && userCaloriesAsInt == 0 {
currentButton = .isZero
return
}
let difference = abs(goalCaloriesAsInt - userCaloriesAsInt)
if difference <= 50 {
currentButton = .goalMet
} else {
currentButton = .goalFailed
}
}
}