Let's say I have this code:
var n = 3
var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
struct ContentView: View {
var body: some View {
Text(String(arr[n])
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
I want to set arr[n] to let's say, 100. Where and how would I go about doing that? I can't put it right after the array declaration since its the top level, and I can't put it inside the ContentView struct.
I'm new to Swift so it would be really helpful if I could get an explanation.
Edit: Additionally if i have this code:
var n = 3
struct ContentView: View {
@State var arr[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
var body: some View {
Text(String(self.arr[n])
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
where would I be able to put self.arr[n] = 0 ?