forked from LoopKit/Loop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNSUserDefaults.swift
132 lines (114 loc) · 4.07 KB
/
NSUserDefaults.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
//
// NSUserDefaults.swift
// Naterade
//
// Created by Nathan Racklyeft on 8/30/15.
// Copyright © 2015 Nathan Racklyeft. All rights reserved.
//
import Foundation
import LoopKit
import HealthKit
extension UserDefaults {
private enum Key: String {
case overrideHistory = "com.loopkit.overrideHistory"
case lastBedtimeQuery = "com.loopkit.Loop.lastBedtimeQuery"
case bedtime = "com.loopkit.Loop.bedtime"
case lastProfileExpirationAlertDate = "com.loopkit.Loop.lastProfileExpirationAlertDate"
case allowDebugFeatures = "com.loopkit.Loop.allowDebugFeatures"
case allowSimulators = "com.loopkit.Loop.allowSimulators"
}
public static let appGroup = UserDefaults(suiteName: Bundle.main.appGroupSuiteName)
public var legacyBasalRateSchedule: BasalRateSchedule? {
get {
if let rawValue = dictionary(forKey: "com.loudnate.Naterade.BasalRateSchedule") {
return BasalRateSchedule(rawValue: rawValue)
} else {
return nil
}
}
}
public var legacyCarbRatioSchedule: CarbRatioSchedule? {
get {
if let rawValue = dictionary(forKey: "com.loudnate.Naterade.CarbRatioSchedule") {
return CarbRatioSchedule(rawValue: rawValue)
} else {
return nil
}
}
}
public var legacyDefaultRapidActingModel: ExponentialInsulinModelPreset? {
get {
if let rawValue = string(forKey: "com.loopkit.Loop.defaultRapidActingModel") {
return ExponentialInsulinModelPreset(rawValue: rawValue)
}
return nil
}
}
public var legacyLoopSettings: LoopSettings? {
get {
if let rawValue = dictionary(forKey: "com.loopkit.Loop.loopSettings") {
return LoopSettings(rawValue: rawValue)
} else {
return nil
}
}
}
public var legacyInsulinSensitivitySchedule: InsulinSensitivitySchedule? {
get {
if let rawValue = dictionary(forKey: "com.loudnate.Naterade.InsulinSensitivitySchedule") {
return InsulinSensitivitySchedule(rawValue: rawValue)
} else {
return nil
}
}
}
public var overrideHistory: TemporaryScheduleOverrideHistory? {
get {
if let rawValue = object(forKey: Key.overrideHistory.rawValue) as? TemporaryScheduleOverrideHistory.RawValue {
return TemporaryScheduleOverrideHistory(rawValue: rawValue)
} else {
return nil
}
}
set {
set(newValue?.rawValue, forKey: Key.overrideHistory.rawValue)
}
}
public var lastBedtimeQuery: Date? {
get {
return object(forKey: Key.lastBedtimeQuery.rawValue) as? Date
}
set {
set(newValue, forKey: Key.lastBedtimeQuery.rawValue)
}
}
public var bedtime: Date? {
get {
return object(forKey: Key.bedtime.rawValue) as? Date
}
set {
set(newValue, forKey: Key.bedtime.rawValue)
}
}
public var lastProfileExpirationAlertDate: Date? {
get {
return object(forKey: Key.lastProfileExpirationAlertDate.rawValue) as? Date
}
set {
set(newValue, forKey: Key.lastProfileExpirationAlertDate.rawValue)
}
}
public var allowDebugFeatures: Bool {
return bool(forKey: Key.allowDebugFeatures.rawValue)
}
public var allowSimulators: Bool {
return bool(forKey: Key.allowSimulators.rawValue)
}
public func removeLegacyLoopSettings() {
removeObject(forKey: "com.loudnate.Naterade.BasalRateSchedule")
removeObject(forKey: "com.loudnate.Naterade.CarbRatioSchedule")
removeObject(forKey: "com.loudnate.Naterade.InsulinSensitivitySchedule")
removeObject(forKey: "com.loopkit.Loop.defaultRapidActingModel")
removeObject(forKey: "com.loopkit.Loop.loopSettings")
}
}