For this, we'll need to define another struct. We can do this in the same file as AddRecipeView.swift, but just directly below our main struct. Start by adding the following snippet, and we'll go through it line by line:
struct AddButton: ViewModifier { @Binding var text: String @Binding var ingredients: [String] public func body(content: Content) -> some View { ZStack(alignment: .trailing) { content Button(action: { if self.text != "" { self.ingredients.append(self.text) self.text = "" } }) { Image(systemName: "plus") .foregroundColor(Color(UIColor.opaqueSeparator)) } .padding(.trailing, 8) } }}
We'll start with the declaration; we create a new struct called AddButton that extends from the ViewModifier ...