I found the following code that an expert posted as a solution for allowing arbitrary numbers of rows in a SwiftUI picker:
struct ContentView: View {
var body: some View {
Picker(selection: $value, label: Text("Pick One")) {
ForEach(Array(stride(from: 1000, through: 20000, by: 1000))) { number in
Text("\(number)").tag(number)
}
}
}
@State var value: Int = 1000
}
Adapting it to my use, I got an error. Cutting and pasting the original code gives me the exact same error, "No exact matches in call to initializer" at the ForEach
's line.
I can fix the error by changing the ForEach
to ForEach(1..<31)
. However, ForEach(1...31)
gives the same error again. Can someone explain these errors?