I have a function that saves data to Firestore:
do {
let decoder = JSONDecoder()
let recipeToDisplay = try decoder.decode(Recipe.self, from: data!)
FirestoreService.createRecipe(
title: recipeToDisplay.title ?? "",
summary: recipeToDisplay.summary ?? "",
instructions: recipeToDisplay.instructions ?? "",
extendedIngredientsImage: recipeToDisplay.extendedIngredients?[0].image ?? "",
extendedIngredientsName: recipeToDisplay.extendedIngredients?[0].name ?? ""
}
}
catch {
print("Error parsing response data: \(error)")}
The function works great, except I’m not sure how I can save every item in the recipeToDisplay.extendedIngredients
array. In the example above, I just specified the 1st item in the array - e.g., recipeToDisplay.extendedIngredients?[0].image
:
But how can I save every item that exists in the array? E.g., recipeToDisplay.extendedIngredients?[0].image
, recipeToDisplay.extendedIngredients?[1].image
, recipeToDisplay.extendedIngredients?[2].image
, etc.