0

I'm creating an app that contains ingredients for foods (simplified version of the app for context of the question). However, I am not sure how to updates values of an array (ingredients).

I have the following struct for each Food that contains a ID(UUID), a name(string), and ingredients(array). I've created a master view for each food as a @State variable and then a detail view which has an edit button that takes you to an edit view with the selected food as a @Binding var.

public struct Food: Hashable, Codable, Identifiable, { public var id = UUID()

var name: String
var ingredients: Array<String>
    

}

In the edit view I'm able to update the name of the food but I can't figure out how to update each individual ingredient. This is the line giving me trouble in the edit view:

ForEach(food.ingredients, id: \.self) { ingredient in
    List {
        TextEditor($ingredient)
                                        
    }
}

Any help would be much appreciated.

tyleroki
  • 191
  • 1
  • 11

0 Answers0