I am using a List
in an app I'm developing. I just discovered that selecting an item from the List
isn't working in iOS 15. It does work in iOS 16, 17 and 18. (I had to download the iOS 16 simulator to test that case.)
Here is a minimum reproducible example:
import SwiftUIstruct ContentView: View { @State var array = ["One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten"] @State var selectedItem: Int? = nil var body: some View { VStack { Text("Snork!") List(Array(array.enumerated()), id: \.offset, selection: $selectedItem) { index, item in Text(item).tag(index) // .tag suggested in comment } .padding() } }}#Preview { ContentView()}
If you run that code on an iOS 17 or 18 simulator, it lets you select a single list item.
If you run it on iOS 15.x, the List
ignores taps. The items are not selectable.
I am still fairly new to SwiftUI. What am I missing?