This is my code:
struct ContentView: View {
// an array of oceans
private var oceans = [
Ocean(name: "Pacific"),
Ocean(name: "Atlantic"),
Ocean(name: "Indian"),
Ocean(name: "Southern"),
Ocean(name: "Arctic")
]
// an array of numbers
private var nums = [1, 2, 3, 4, 5]
var body: some View {
VStack{
List(oceans) { ocean in
Text("(ocean.name)")
}
List(nums) { num in // error appears here
}
}//VStack
}
I tried to call
List(nums) { num in }
But it won’t let me and gave me the error of Cannot convert value of type ‘[Int]’ to expected argument type ‘Range. Do you know why it works with oceans but not nums?
New contributor
Elaine Chen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.