WatchData.swift 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. struct WatchState: Hashable, Equatable, Sendable {
  2. var currentGlucose: String?
  3. var trend: String?
  4. var delta: String?
  5. var glucoseValues: [(date: Date, glucose: Double)] = []
  6. var units: GlucoseUnits = .mmolL
  7. var iob: Decimal = 0 // Insulin on Board
  8. var cob: Int = 0 // Carbs on Board
  9. static func == (lhs: WatchState, rhs: WatchState) -> Bool {
  10. lhs.currentGlucose == rhs.currentGlucose &&
  11. lhs.trend == rhs.trend &&
  12. lhs.delta == rhs.delta &&
  13. lhs.glucoseValues.count == rhs.glucoseValues.count &&
  14. zip(lhs.glucoseValues, rhs.glucoseValues).allSatisfy {
  15. $0.0.date == $0.1.date && $0.0.glucose == $0.1.glucose
  16. } &&
  17. lhs.units == rhs.units &&
  18. lhs.iob == rhs.iob &&
  19. lhs.cob == rhs.cob
  20. }
  21. func hash(into hasher: inout Hasher) {
  22. hasher.combine(currentGlucose)
  23. hasher.combine(trend)
  24. hasher.combine(delta)
  25. for value in glucoseValues {
  26. hasher.combine(value.date)
  27. hasher.combine(value.glucose)
  28. }
  29. hasher.combine(units)
  30. hasher.combine(iob)
  31. hasher.combine(cob)
  32. }
  33. }