CarbsGlucose+helper.swift 497 B

123456789101112131415161718
  1. import Foundation
  2. struct CarbAndGlucose: Encodable {
  3. let carbs: Decimal
  4. let glucose: Decimal
  5. enum CodingKeys: String, CodingKey {
  6. case carbs
  7. case glucose
  8. }
  9. func encode(to encoder: Encoder) throws {
  10. var container = encoder.container(keyedBy: CodingKeys.self)
  11. try container.encode(NSDecimalNumber(decimal: carbs).stringValue, forKey: .carbs)
  12. try container.encode(NSDecimalNumber(decimal: glucose).stringValue, forKey: .glucose)
  13. }
  14. }