Post

Replies

Boosts

Views

Activity

Reply to Why the first item I tap on a SwiftUI List becomes nil when present it in a sheet
You need to use item instead of isPresented, which means you trigger the sheet by assigning/updating the selected value, instead of toggling a boolean value. In code that would be something like this. struct UpdateStateProperty: View {   var items:[Item] = [Item(name: "Oranges"),             Item(name: "Apples"),             Item(name: "Cookies") ]   @State private var presentView = false   @State private var selectedItem: Item?   var body: some View {     List{       ForEach(items){ item in         HStack{           Text(item.name)         }.onTapGesture {           selectedItem = item         }       }     }     .sheet(item: $selectedItem) { item in       Text("\(item?.name ?? "")")     }   } } I haven't tested the above code, just copied yours, but you got the idea.
Feb ’22