I have a model called Hobby. I want to create a view that interates over all of the hobbies and displays each in a box in a scrolling HStack.
My code looks like this:
struct HobbiesHStack: View {
@Environment(\.modelContext) var context
@Query(sort: \Hobby.createdDate) private var hobbies: [Hobby]
var body: some View {
HStack(spacing: 15) {
ForEach(hobbies, id: \.self) { hobby in
HobbyBox(hobby: hobby)
}
}
}
}
This works fine. Except that now I want to add some functionality in that scrolling HStack which allows me to edit or add items to the Hobby model. So I think I want to create a binding on hobby that allows for the values to be in sync accross many different view. As I iterate throught the hobbies, I want to pass a binding of hobby to the HobbyBox subview.
Is this possible? Or even a good way to do it?