Fixed some bugs, but ambiguous types are there

This commit is contained in:
cdricms
2023-12-15 23:38:36 +01:00
parent 2f919ffdef
commit e699d71597
13 changed files with 294 additions and 233 deletions

View File

@@ -1,13 +1,15 @@
// public struct Images: Codable { import Foundation
// private var otherData: [String: Data] = [:]
// mutating func setDetail<T: Encodable>(key: String, value: T) throws { public struct Images: Codable {
// let encodedValue = try JSONEncoder().encode(value) public var otherData: [String: Data] = [:]
// otherData[key] = encodedValue
// }
// func getDetail<T: Decodable>(key: String, type: T.Type) throws -> T? { mutating func setDetail<T: Encodable>(key: String, value: T) throws {
// guard let data = otherData[key] else { return nil } let encodedValue = try JSONEncoder().encode(value)
// return try JSONDecoder().decode(type, from: data) otherData[key] = encodedValue
// } }
// }
func getDetail<T: Decodable>(key: String, type: T.Type) throws -> T? {
guard let data = otherData[key] else { return nil }
return try JSONDecoder().decode(type, from: data)
}
}

View File

@@ -1,4 +1,4 @@
public struct Ingredient: Codable { public struct Ingredient: Codable, ObjectDebugger {
public var fromPalmOil: String? = nil public var fromPalmOil: String? = nil
public var id: String? = nil public var id: String? = nil
public var origin: String? = nil public var origin: String? = nil

View File

@@ -1,6 +1,6 @@
public struct LanguagesCodes: Codable { public struct LanguagesCodes: Codable, ObjectDebugger {
public var en: String? = nil public var en: Int? = nil
public var fr: String? = nil public var fr: Int? = nil
public var pl: String? = nil public var pl: Int? = nil
} }

View File

@@ -1,4 +1,4 @@
public struct NutrientLevels: Codable { public struct NutrientLevels: Codable, ObjectDebugger {
public var fat: String? = nil public var fat: String? = nil
public var salt: String? = nil public var salt: String? = nil
public var saturatedFat: String? = nil public var saturatedFat: String? = nil

View File

@@ -1,4 +1,4 @@
public struct Nutriments: Codable { public struct Nutriments: Codable, ObjectDebugger {
public var calcium: Float? = 0.0 public var calcium: Float? = 0.0
public var calciumValue: Float? = 0.0 public var calciumValue: Float? = 0.0
public var calcium100G: Float? = 0.0 public var calcium100G: Float? = 0.0
@@ -27,9 +27,9 @@ public struct Nutriments: Codable {
public var energyValue: Int? = 0 public var energyValue: Int? = 0
public var energyKcalValue: Int? = 0 public var energyKcalValue: Int? = 0
public var energyKjValue: Int? = 0 public var energyKjValue: Int? = 0
public var energy100G: Int? = 0 public var energy100G: Float? = 0
public var energyKcal100G: Int? = 0 public var energyKcal100G: Int? = 0
public var energyKj100G: Int? = 0 public var energyKj100G: Float? = 0
public var energyServing: Int? = 0 public var energyServing: Int? = 0
public var energyKcalServing: Double? = 0.0 public var energyKcalServing: Double? = 0.0
public var energyKjServing: Int? = 0 public var energyKjServing: Int? = 0

View File

@@ -0,0 +1,57 @@
public protocol ObjectDebugger: CustomStringConvertible {
var description: String { get }
}
public extension ObjectDebugger {
var description: String {
var description = "\(type(of: self))("
let mirror = Mirror(reflecting: self)
for (label, value) in mirror.children {
if let label = label {
description += "\(label): \(value), "
}
}
// Remove the trailing comma and space
description = String(description.dropLast(2))
description += ")"
return description
}
private func prettyPrint(object: Any, indentation: String = "") -> String {
var description = "\(type(of: object)) {"
let mirror = Mirror(reflecting: object)
for (label, value) in mirror.children {
if let label = label {
let childDescription: String
switch value {
case let nestedObject as CustomStringConvertible:
childDescription = prettyPrint(object: nestedObject, indentation: "\(indentation) ")
case let stringValue as String:
childDescription = "\"\(stringValue)\""
case let floatValue as Float:
childDescription = "\(floatValue)"
case let intValue as Int:
childDescription = "\(intValue)"
case let optionalValue as CustomStringConvertible?:
if let unwrapped = optionalValue {
childDescription = "\(unwrapped)"
} else {
childDescription = "nil"
}
default:
childDescription = "\(value)"
}
description += "\n\(indentation) \(label): \(childDescription)"
}
}
description += "\n\(indentation)}"
return description
}
}

View File

@@ -1,5 +1,5 @@
public class Product: Codable { public class Product: Codable, ObjectDebugger {
// var images: Images? = Images() // public var images: Images? = Images()
public var ingredients: [Ingredient]? = [] public var ingredients: [Ingredient]? = []
public var languagesCodes: LanguagesCodes? public var languagesCodes: LanguagesCodes?
public var nutrientLevels: NutrientLevels? public var nutrientLevels: NutrientLevels?
@@ -24,7 +24,7 @@ public class Product: Codable {
public var brands: String? public var brands: String?
public var brandsDebugTags: [String]? public var brandsDebugTags: [String]?
public var brandsTags: [String]? public var brandsTags: [String]?
public var carbonFootprintPercentOfKnownIngredients: String? public var carbonFootprintPercentOfKnownIngredients: Float?
public var carbonFootprintFromKnownIngredientsDebug: String? public var carbonFootprintFromKnownIngredientsDebug: String?
public var categories: String? public var categories: String?
public var categoriesHierarchy: [String]? public var categoriesHierarchy: [String]?
@@ -133,7 +133,7 @@ public class Product: Codable {
public var nutritionDataPer: String? public var nutritionDataPer: String?
public var nutritionScoreWarningNoFruitsVegetablesNuts: Int? public var nutritionScoreWarningNoFruitsVegetablesNuts: Int?
public var noNutritionData: String? public var noNutritionData: String?
public var novaGroup: String? public var novaGroup: Int?
public var novaGroups: String? public var novaGroups: String?
public var novaGroupDebug: String? public var novaGroupDebug: String?
public var novaGroupTags: [String]? public var novaGroupTags: [String]?
@@ -197,204 +197,204 @@ public class Product: Codable {
public var updateKey: String? public var updateKey: String?
public var vitaminsPrevTags: [String]? public var vitaminsPrevTags: [String]?
public var vitaminsTags: [String]? public var vitaminsTags: [String]?
}
private enum CodingKeys: String, CodingKey { private enum CodingKeys: String, CodingKey {
case images // case images
case ingredients case ingredients
case languagesCodes = "languages_codes" case languagesCodes = "languages_codes"
case nutrientLevels = "nutrient_levels" case nutrientLevels = "nutrient_levels"
case nutriments case nutriments
case selectedImages = "selected_images" case selectedImages = "selected_images"
case sources case sources
case additivesN = "additives_n" case additivesN = "additives_n"
case additivesOldN = "additives_old_n" case additivesOldN = "additives_old_n"
case additivesOriginalTags = "additives_original_tags" case additivesOriginalTags = "additives_original_tags"
case additivesOldTags = "additives_old_tags" case additivesOldTags = "additives_old_tags"
case additivesPrevOriginalTags = "additives_prev_original_tags" case additivesPrevOriginalTags = "additives_prev_original_tags"
case additivesDebugTags = "additives_debug_tags" case additivesDebugTags = "additives_debug_tags"
case additivesTags = "additives_tags" case additivesTags = "additives_tags"
case allergens case allergens
case allergensFromIngredients = "allergens_from_ingredients" case allergensFromIngredients = "allergens_from_ingredients"
case allergensFromUser = "allergens_from_user" case allergensFromUser = "allergens_from_user"
case allergensHierarchy = "allergens_hierarchy" case allergensHierarchy = "allergens_hierarchy"
case allergensLc = "allergens_lc" case allergensLc = "allergens_lc"
case allergensTags = "allergens_tags" case allergensTags = "allergens_tags"
case aminoAcidsPrevTags = "amino_acids_prev_tags" case aminoAcidsPrevTags = "amino_acids_prev_tags"
case aminoAcidsTags = "amino_acids_tags" case aminoAcidsTags = "amino_acids_tags"
case brands case brands
case brandsDebugTags = "brands_debug_tags" case brandsDebugTags = "brands_debug_tags"
case brandsTags = "brands_tags" case brandsTags = "brands_tags"
case carbonFootprintPercentOfKnownIngredients = "carbon_footprint_percent_of_known_ingredients" case carbonFootprintPercentOfKnownIngredients = "carbon_footprint_percent_of_known_ingredients"
case carbonFootprintFromKnownIngredientsDebug = "carbon_footprint_from_known_ingredients_debug" case carbonFootprintFromKnownIngredientsDebug = "carbon_footprint_from_known_ingredients_debug"
case categories case categories
case categoriesHierarchy = "categories_hierarchy" case categoriesHierarchy = "categories_hierarchy"
case categoriesLc = "categories_lc" case categoriesLc = "categories_lc"
case categoriesPropertiesTags = "categories_properties_tags" case categoriesPropertiesTags = "categories_properties_tags"
case categoriesTags = "categories_tags" case categoriesTags = "categories_tags"
case checkersTags = "checkers_tags" case checkersTags = "checkers_tags"
case citiesTags = "cities_tags" case citiesTags = "cities_tags"
case code case code
case codesTags = "codes_tags" case codesTags = "codes_tags"
case comparedToCategory = "compared_to_category" case comparedToCategory = "compared_to_category"
case complete case complete
case completedT = "completed_t" case completedT = "completed_t"
case completeness case completeness
case conservationConditions = "conservation_conditions" case conservationConditions = "conservation_conditions"
case countries case countries
case countriesHierarchy = "countries_hierarchy" case countriesHierarchy = "countries_hierarchy"
case countriesLc = "countries_lc" case countriesLc = "countries_lc"
case countriesDebugTags = "countries_debug_tags" case countriesDebugTags = "countries_debug_tags"
case countriesTags = "countries_tags" case countriesTags = "countries_tags"
case correctorsTags = "correctors_tags" case correctorsTags = "correctors_tags"
case createdT = "created_t" case createdT = "created_t"
case creator case creator
case dataQualityBugsTags = "data_quality_bugs_tags" case dataQualityBugsTags = "data_quality_bugs_tags"
case dataQualityErrorsTags = "data_quality_errors_tags" case dataQualityErrorsTags = "data_quality_errors_tags"
case dataQualityInfoTags = "data_quality_info_tags" case dataQualityInfoTags = "data_quality_info_tags"
case dataQualityTags = "data_quality_tags" case dataQualityTags = "data_quality_tags"
case dataQualityWarningsTags = "data_quality_warnings_tags" case dataQualityWarningsTags = "data_quality_warnings_tags"
case dataSources = "data_sources" case dataSources = "data_sources"
case dataSourcesTags = "data_sources_tags" case dataSourcesTags = "data_sources_tags"
case debugParamSortedLangs = "debug_param_sorted_langs" case debugParamSortedLangs = "debug_param_sorted_langs"
case editorsTags = "editors_tags" case editorsTags = "editors_tags"
case embCodes = "emb_codes" case embCodes = "emb_codes"
case embCodesDebugTags = "emb_codes_debug_tags" case embCodesDebugTags = "emb_codes_debug_tags"
case embCodesOrig = "emb_codes_orig" case embCodesOrig = "emb_codes_orig"
case embCodesTags = "emb_codes_tags" case embCodesTags = "emb_codes_tags"
case entryDatesTags = "entry_dates_tags" case entryDatesTags = "entry_dates_tags"
case expirationDate = "expiration_date" case expirationDate = "expiration_date"
case expirationDateDebugTags = "expiration_date_debug_tags" case expirationDateDebugTags = "expiration_date_debug_tags"
case fruitsVegetablesNuts100GEstimate = "fruits-vegetables-nuts_100g_estimate" case fruitsVegetablesNuts100GEstimate = "fruits-vegetables-nuts_100g_estimate"
case genericName case genericName
case id case id
case imageFrontSmallUrl = "image_front_small_url" case imageFrontSmallUrl = "image_front_small_url"
case imageFrontThumbUrl = "image_front_thumb_url" case imageFrontThumbUrl = "image_front_thumb_url"
case imageFrontUrl = "image_front_url" case imageFrontUrl = "image_front_url"
case imageIngredientsUrl = "image_ingredients_url" case imageIngredientsUrl = "image_ingredients_url"
case imageIngredientsSmallUrl = "image_ingredients_small_url" case imageIngredientsSmallUrl = "image_ingredients_small_url"
case imageIngredientsThumbUrl = "image_ingredients_thumb_url" case imageIngredientsThumbUrl = "image_ingredients_thumb_url"
case imageNutritionSmallUrl = "image_nutrition_small_url" case imageNutritionSmallUrl = "image_nutrition_small_url"
case imageNutritionThumbUrl = "image_nutrition_thumb_url" case imageNutritionThumbUrl = "image_nutrition_thumb_url"
case imageNutritionUrl = "image_nutrition_url" case imageNutritionUrl = "image_nutrition_url"
case imageSmallUrl = "image_small_url" case imageSmallUrl = "image_small_url"
case imageThumbUrl = "image_thumb_url" case imageThumbUrl = "image_thumb_url"
case imageUrl = "image_url" case imageUrl = "image_url"
case informersTags = "informers_tags" case informersTags = "informers_tags"
case ingredientsAnalysisTags = "ingredients_analysis_tags" case ingredientsAnalysisTags = "ingredients_analysis_tags"
case ingredientsDebug = "ingredients_debug" case ingredientsDebug = "ingredients_debug"
case ingredientsFromOrThatMayBeFromPalmOilN = "ingredients_from_or_that_may_be_from_palm_oil_n" case ingredientsFromOrThatMayBeFromPalmOilN = "ingredients_from_or_that_may_be_from_palm_oil_n"
case ingredientsFromPalmOilTags = "ingredients_from_palm_oil_tags" case ingredientsFromPalmOilTags = "ingredients_from_palm_oil_tags"
case ingredientsFromPalmOilN = "ingredients_from_palm_oil_n" case ingredientsFromPalmOilN = "ingredients_from_palm_oil_n"
case ingredientsHierarchy = "ingredients_hierarchy" case ingredientsHierarchy = "ingredients_hierarchy"
case ingredientsIdsDebug = "ingredients_ids_debug" case ingredientsIdsDebug = "ingredients_ids_debug"
case ingredientsN = "ingredients_n" case ingredientsN = "ingredients_n"
case ingredientsNTags = "ingredients_n_tags" case ingredientsNTags = "ingredients_n_tags"
case ingredientsOriginalTags = "ingredients_original_tags" case ingredientsOriginalTags = "ingredients_original_tags"
case ingredientsTags = "ingredients_tags" case ingredientsTags = "ingredients_tags"
case ingredientsText = "ingredients_text" case ingredientsText = "ingredients_text"
case ingredientsTextDebug = "ingredients_text_debug" case ingredientsTextDebug = "ingredients_text_debug"
case ingredientsTextWithAllergens = "ingredients_text_with_allergens" case ingredientsTextWithAllergens = "ingredients_text_with_allergens"
case ingredientsThatMayBeFromPalmOilN = "ingredients_that_may_be_from_palm_oil_n" case ingredientsThatMayBeFromPalmOilN = "ingredients_that_may_be_from_palm_oil_n"
case ingredientsThatMayBeFromPalmOilTags = "ingredients_that_may_be_from_palm_oil_tags" case ingredientsThatMayBeFromPalmOilTags = "ingredients_that_may_be_from_palm_oil_tags"
case interfaceVersionCreated = "interface_version_created" case interfaceVersionCreated = "interface_version_created"
case interfaceVersionModified = "interface_version_modified" case interfaceVersionModified = "interface_version_modified"
case keywords case keywords
case knownIngredientsN = "known_ingredients_n" case knownIngredientsN = "known_ingredients_n"
case labels case labels
case labelsHierarchy = "labels_hierarchy" case labelsHierarchy = "labels_hierarchy"
case labelsLc = "labels_lc" case labelsLc = "labels_lc"
case labelsPrevHierarchy = "labels_prev_hierarchy" case labelsPrevHierarchy = "labels_prev_hierarchy"
case labelsPrevTags = "labels_prev_tags" case labelsPrevTags = "labels_prev_tags"
case labelsTags = "labels_tags" case labelsTags = "labels_tags"
case labelsDebugTags = "labels_debug_tags" case labelsDebugTags = "labels_debug_tags"
case lang case lang
case langDebugTags = "lang_debug_tags" case langDebugTags = "lang_debug_tags"
case languagesHierarchy = "languages_hierarchy" case languagesHierarchy = "languages_hierarchy"
case languagesTags = "languages_tags" case languagesTags = "languages_tags"
case lastEditDatesTags = "last_edit_dates_tags" case lastEditDatesTags = "last_edit_dates_tags"
case lastEditor = "last_editor" case lastEditor = "last_editor"
case lastImageDatesTags = "last_image_dates_tags" case lastImageDatesTags = "last_image_dates_tags"
case lastImageT = "last_image_t" case lastImageT = "last_image_t"
case lastModifiedBy = "last_modified_by" case lastModifiedBy = "last_modified_by"
case lastModifiedT = "last_modified_t" case lastModifiedT = "last_modified_t"
case lc case lc
case link case link
case linkDebugTags = "link_debug_tags" case linkDebugTags = "link_debug_tags"
case manufacturingPlaces = "manufacturing_places" case manufacturingPlaces = "manufacturing_places"
case manufacturingPlacesDebugTags = "manufacturing_places_debug_tags" case manufacturingPlacesDebugTags = "manufacturing_places_debug_tags"
case manufacturingPlacesTags = "manufacturing_places_tags" case manufacturingPlacesTags = "manufacturing_places_tags"
case maxImgid = "max_imgid" case maxImgid = "max_imgid"
case mineralsPrevTags = "minerals_prev_tags" case mineralsPrevTags = "minerals_prev_tags"
case mineralsTags = "minerals_tags" case mineralsTags = "minerals_tags"
case miscTags = "misc_tags" case miscTags = "misc_tags"
case netWeightUnit = "net_weight_unit" case netWeightUnit = "net_weight_unit"
case netWeightValue = "net_weight_value" case netWeightValue = "net_weight_value"
case nutritionDataPer = "nutrition_data_per" case nutritionDataPer = "nutrition_data_per"
case nutritionScoreWarningNoFruitsVegetablesNuts = "nutrition_score_warning_no_fruits_vegetables_nuts" case nutritionScoreWarningNoFruitsVegetablesNuts = "nutrition_score_warning_no_fruits_vegetables_nuts"
case noNutritionData = "no_nutrition_data" case noNutritionData = "no_nutrition_data"
case novaGroup = "nova_group" case novaGroup = "nova_group"
case novaGroups = "nova_groups" case novaGroups = "nova_groups"
case novaGroupDebug = "nova_group_debug" case novaGroupDebug = "nova_group_debug"
case novaGroupTags = "nova_group_tags" case novaGroupTags = "nova_group_tags"
case novaGroupsTags = "nova_groups_tags" case novaGroupsTags = "nova_groups_tags"
case nucleotidesPrevTags = "nucleotides_prev_tags" case nucleotidesPrevTags = "nucleotides_prev_tags"
case nucleotidesTags = "nucleotides_tags" case nucleotidesTags = "nucleotides_tags"
case nutrientLevelsTags = "nutrient_levels_tags" case nutrientLevelsTags = "nutrient_levels_tags"
case nutritionData = "nutrition_data" case nutritionData = "nutrition_data"
case nutritionDataPerDebugTags = "nutrition_data_per_debug_tags" case nutritionDataPerDebugTags = "nutrition_data_per_debug_tags"
case nutritionDataPrepared = "nutrition_data_prepared" case nutritionDataPrepared = "nutrition_data_prepared"
case nutritionDataPreparedPer = "nutrition_data_prepared_per" case nutritionDataPreparedPer = "nutrition_data_prepared_per"
case nutritionGrades = "nutrition_grades" case nutritionGrades = "nutrition_grades"
case nutritionScoreBeverage = "nutrition_score_beverage" case nutritionScoreBeverage = "nutrition_score_beverage"
case nutritionScoreDebug = "nutrition_score_debug" case nutritionScoreDebug = "nutrition_score_debug"
case nutritionScoreWarningNoFiber = "nutrition_score_warning_no_fiber" case nutritionScoreWarningNoFiber = "nutrition_score_warning_no_fiber"
case nutritionGradesTags = "nutrition_grades_tags" case nutritionGradesTags = "nutrition_grades_tags"
case origins case origins
case originsDebugTags = "origins_debug_tags" case originsDebugTags = "origins_debug_tags"
case originsTags = "origins_tags" case originsTags = "origins_tags"
case otherInformation = "other_information" case otherInformation = "other_information"
case otherNutritionalSubstancesTags = "other_nutritional_substances_tags" case otherNutritionalSubstancesTags = "other_nutritional_substances_tags"
case packaging case packaging
case packagingDebugTags = "packaging_debug_tags" case packagingDebugTags = "packaging_debug_tags"
case packagingTags = "packaging_tags" case packagingTags = "packaging_tags"
case photographersTags = "photographers_tags" case photographersTags = "photographers_tags"
case pnnsGroups1 = "pnns_groups_1" case pnnsGroups1 = "pnns_groups_1"
case pnnsGroups2 = "pnns_groups_2" case pnnsGroups2 = "pnns_groups_2"
case pnnsGroups1Tags = "pnns_groups_1_tags" case pnnsGroups1Tags = "pnns_groups_1_tags"
case pnnsGroups2Tags = "pnns_groups_2_tags" case pnnsGroups2Tags = "pnns_groups_2_tags"
case popularityKey = "popularity_key" case popularityKey = "popularity_key"
case producerVersionId = "producer_version_id" case producerVersionId = "producer_version_id"
case productName = "product_name" case productName = "product_name"
case productQuantity = "product_quantity" case productQuantity = "product_quantity"
case purchasePlaces = "purchase_places" case purchasePlaces = "purchase_places"
case purchasePlacesDebugTags = "purchase_places_debug_tags" case purchasePlacesDebugTags = "purchase_places_debug_tags"
case purchasePlacesTags = "purchase_places_tags" case purchasePlacesTags = "purchase_places_tags"
case qualityTags = "quality_tags" case qualityTags = "quality_tags"
case quantity case quantity
case quantityDebugTags = "quantity_debug_tags" case quantityDebugTags = "quantity_debug_tags"
case recyclingInstructionsToDiscard = "recycling_instructions_to_discard" case recyclingInstructionsToDiscard = "recycling_instructions_to_discard"
case rev case rev
case servingQuantity = "serving_quantity" case servingQuantity = "serving_quantity"
case servingSize = "serving_size" case servingSize = "serving_size"
case servingSizeDebugTags = "serving_size_debug_tags" case servingSizeDebugTags = "serving_size_debug_tags"
case sortkey case sortkey
case states case states
case statesHierarchy = "states_hierarchy" case statesHierarchy = "states_hierarchy"
case statesTags = "states_tags" case statesTags = "states_tags"
case stores case stores
case storesDebugTags = "stores_debug_tags" case storesDebugTags = "stores_debug_tags"
case storesTags = "stores_tags" case storesTags = "stores_tags"
case traces case traces
case tracesFromIngredients = "traces_from_ingredients" case tracesFromIngredients = "traces_from_ingredients"
case tracesHierarchy = "traces_hierarchy" case tracesHierarchy = "traces_hierarchy"
case tracesDebugTags = "traces_debug_tags" case tracesDebugTags = "traces_debug_tags"
case tracesFromUser = "traces_from_user" case tracesFromUser = "traces_from_user"
case tracesLc = "traces_lc" case tracesLc = "traces_lc"
case tracesTags = "traces_tags" case tracesTags = "traces_tags"
case unknownIngredientsN = "unknown_ingredients_n" case unknownIngredientsN = "unknown_ingredients_n"
case unknownNutrientsTags = "unknown_nutrients_tags" case unknownNutrientsTags = "unknown_nutrients_tags"
case updateKey = "update_key" case updateKey = "update_key"
case vitaminsPrevTags = "vitamins_prev_tags" case vitaminsPrevTags = "vitamins_prev_tags"
case vitaminsTags = "vitamins_tags" case vitaminsTags = "vitamins_tags"
}
} }

View File

@@ -1,5 +1,5 @@
public struct ProductResponse: Codable { public struct ProductResponse: Codable, ObjectDebugger {
public var product: Product? public var product: Product?
public var code: String? public var code: String?
public var status: Int? // or Bool, depending on your needs public var status: Int? // or Bool, depending on your needs

View File

@@ -1,4 +1,4 @@
public class SelectedImage: Codable { public class SelectedImage: Codable, ObjectDebugger {
public var display: SelectedImageItem? public var display: SelectedImageItem?
public var small: SelectedImageItem? public var small: SelectedImageItem?
public var thumb: SelectedImageItem? public var thumb: SelectedImageItem?

View File

@@ -1,4 +1,4 @@
public struct SelectedImageItem: Codable { public struct SelectedImageItem: Codable, ObjectDebugger {
public let en: String? public let en: String?
public let fr: String? public let fr: String?
public let pl: String? public let pl: String?

View File

@@ -1,4 +1,4 @@
public struct SelectedImages: Codable { public struct SelectedImages: Codable, ObjectDebugger {
public let front: SelectedImage? public let front: SelectedImage?
public let ingredients: SelectedImage? public let ingredients: SelectedImage?
public let nutrition: SelectedImage? public let nutrition: SelectedImage?

View File

@@ -1,4 +1,4 @@
public struct Source: Codable { public struct Source: Codable, ObjectDebugger {
public let fields: [String] = [] public let fields: [String] = []
public let id: String? = nil public let id: String? = nil
public let images: [String] = [] public let images: [String] = []

View File

@@ -3,9 +3,11 @@ import OpenFoodFacts
let off = OpenFoodFactsClient() let off = OpenFoodFactsClient()
do { for barcode in ["0737628064502", "0812133010036", "0849092103196", "22007377", "3033610048398", "3222473161867", "3242272260059", "3245412470929", "3502110000880", "3551100749018", "3560070805259", "3560070976867", "3596710352418", "3800020430781", "4000539770708", "4388858946739", "5010251168577", "5015821151720", "5050854517631", "5054070608074", "5201051001076", "5410228196693", "5449000179661"] {
let res = try await off.getProductByBarcode("3017620422003") do {
print(res.product!.nutriments!.energy!) try await off.getProductByBarcode(barcode)
} catch { // print(res.product!)
print("\(error)") } catch {
print("[BARCODE: \(barcode)]\(error)")
}
} }