Files
swift-openfoodfacts-sdk/Sources/OpenFoodFactsSDK/Schemas/NutriscoreData.swift
cdricms 44420002c7 😑
2025-12-06 18:15:17 +01:00

46 lines
1.4 KiB
Swift

public struct NutriscoreData: Sendable, Codable {
public let saturatedFatRatio: Float?
public let saturatedFatRatioPoints: Int?
public let saturatedFatRatioValue: Float?
public let isBeverage: Int?
public let isCheese: Int?
public let isWater: Int?
public let isFat: Int?
public let energy: Int?
// ...
public enum CodingKeys: String, CodingKey {
case saturatedFatRatio = "saturated_fat_ratio"
case saturatedFatRatioPoints = "saturated_fat_ratio_points"
case saturatedFatRatioValue = "saturated_fat_ratio_value"
case isBeverage = "is_beverage"
case isCheese = "is_cheese"
case isWater = "is_water"
case isFat = "is_fat"
case energy
}
public init(from decoder: any Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
saturatedFatRatio = try container.decodeIfPresent(
Float.self, forKey: .saturatedFatRatio)
saturatedFatRatioPoints = try container.decodeIfPresent(
Int.self, forKey: .saturatedFatRatioPoints)
saturatedFatRatioValue = try container.decodeIfPresent(
Float.self, forKey: .saturatedFatRatioValue)
isBeverage = try container.decodeIfPresent(
Int.self, forKey: .isBeverage)
isCheese = try container.decodeStringOrInt(forKey: .isCheese)
isWater = try container.decodeStringOrInt(forKey: .isWater)
isFat = try container.decodeStringOrInt(forKey: .isFat)
energy = try container.decodeStringOrInt(forKey: .energy)
}
}