I have some lines of code below where I can make multiple selections.
import SwiftUI
struct ContentView: View {
@State private var selectedUsers: Set<String> = []
@State var users = ["Susan", "Kate", "Natalie", "Kimberly", "Taylor", "Sarah", "Nancy", "Katherine", "Nicole", "Linda", "Jane", "Mary", "Olivia", "Barbara"]
var body: some View {
VStack {
List(selection: $selectedUsers) {
ForEach(users, id: \.self) { user in
Text(user)
}
}
.environment(\.editMode, .constant(.active))
}
}
}
So the blue selection symbol appears as shown in the screenshot above. That's good. But that's not what I'm after. I just want to select one row at a time.
import SwiftUI
struct ContentView: View {
@State var selectedUser: String?
@State var users = ["Susan", "Kate", "Natalie", "Kimberly", "Taylor", "Sarah", "Nancy", "Katherine", "Nicole", "Linda", "Jane", "Mary", "Olivia", "Barbara"]
var body: some View {
VStack {
List(selection: $selectedUser) {
ForEach(users, id: \.self) { user in
Text(user)
}
}
.environment(\.editMode, .constant(.active))
}
}
}
In the lines of code above, I only let myself select one row at a time. And I don't get the blue selection symbol. I wonder why? I find two or three websites where they have similar lines of code and where they select one row at a time. And they have the blue selection symbol. Why don't I get it?
Mucho thankos for reading.