UserDefaultsExtensions.swift 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import Foundation
  2. import LoopKit
  3. import RileyLinkBLEKit
  4. import RileyLinkKit
  5. extension UserDefaults {
  6. private enum Key: String {
  7. case legacyPumpManagerRawValue = "com.rileylink.PumpManagerRawValue"
  8. case rileyLinkConnectionManagerState = "com.rileylink.RileyLinkConnectionManagerState"
  9. case legacyPumpManagerState = "com.loopkit.Loop.PumpManagerState"
  10. case legacyCGMManagerState = "com.loopkit.Loop.CGMManagerState"
  11. }
  12. var rileyLinkConnectionManagerState: RileyLinkConnectionState? {
  13. get {
  14. guard let rawValue = dictionary(forKey: Key.rileyLinkConnectionManagerState.rawValue)
  15. else {
  16. return nil
  17. }
  18. return RileyLinkConnectionState(rawValue: rawValue)
  19. }
  20. set {
  21. set(newValue?.rawValue, forKey: Key.rileyLinkConnectionManagerState.rawValue)
  22. }
  23. }
  24. var legacyPumpManagerRawValue: PumpManager.RawValue? {
  25. dictionary(forKey: Key.legacyPumpManagerRawValue.rawValue)
  26. }
  27. func clearLegacyPumpManagerRawValue() {
  28. set(nil, forKey: Key.legacyPumpManagerRawValue.rawValue)
  29. }
  30. var legacyCGMManagerRawValue: CGMManager.RawValue? {
  31. dictionary(forKey: Key.legacyCGMManagerState.rawValue)
  32. }
  33. func clearLegacyCGMManagerRawValue() {
  34. set(nil, forKey: Key.legacyCGMManagerState.rawValue)
  35. }
  36. }