SwiftUI: Issues with using @EnvironmentObject and List row selection causing unexpected behavior in iOS 17
I'm stuck on something that should probably be simple. I'm having trouble implementing a `List` in SwiftUI with an `@EnvironmentObject` that manages the selected state of rows. When I tap on a row, it should update the selection and reflect changes in the UI, but I'm experiencing unexpected behavior where the selection does not consistently update after the initial tap. Here's a simplified version of my setup: ```swift class SelectionModel: ObservableObject { @Published var selectedItem: Item? } struct Item: Identifiable { let id: UUID let name: String } struct ContentView: View { @EnvironmentObject var selectionModel: SelectionModel let items: [Item] var body: some View { List(items) { item in HStack { Text(item.name) if selectionModel.selectedItem == item { Spacer() Image(systemName: "checkmark") } } .contentShape(Rectangle()) .onTapGesture { selectionModel.selectedItem = selectionModel.selectedItem == item ? nil : item } } } } ``` I've added the checkmark to indicate the selected item, but when I select an item, the checkmark doesn't appear until I tap another row. The `selectedItem` does update, but the UI doesn't reflect this until a second interaction. I tried adding `.id(selectionModel.selectedItem?.id)` to the `List`, but that didn't seem to fix the issue either. I want to achieve instant UI feedback upon selection. Is there a known issue with `@EnvironmentObject` and `List` in iOS 17 that's causing this, or am I missing something in my implementation? Any guidance would be appreciated! Any help would be greatly appreciated! My development environment is Ubuntu. Am I missing something obvious? The stack includes Swift and several other technologies. I'd be grateful for any help.