This code works in an Xcode 12.5 playground on BigSur 11.2.3 on an M1 mac:
import UIKit
var Choice = Array(repeating: "" , count: 3)
Choice [0] = """
This is the land of Gaul
The people are tall
and the children are small
"""
Choice [1] = """
This is the land of Anglos
The people wear black clothes
and they never eat mangoes
"""
Choice [2] = """
This is the land of Hesperia
The people drink their vangueria
and never suffer hysteria
"""
print(Choice [1])
However, when it is in a swiftUI view like so:
import SwiftUI
struct ThirdCalcView: View {
@State private var selectedChoice = 0
var str1 = """
This goes
over multiple
lines
"""
var Choice = Array(repeating: "" , count: 3)
Choice [0] = """
This is the land of Gaul
The people are tall
and the children are small
"""
Choice [1] = """
This is the land of Anglos
The people wear black clothes
and they never eat mangoes
"""
Choice [2] = """
This is the land of Hesperia
The people drink their vangueria
and never suffer hysteria
"""
var body: some View {
Form {
Section {
Picker("Choice", selection: $selectedChoice, content: {
Text("France").tag(0)
Text("England").tag(1)
Text("Spain").tag(2)
})
}//section
Section {
Text("The mnemonic is:\(Choice[selectedChoice])")
}//section
} //form
}//some view
} //ThirdCalcView
struct ThirdCalcView_Previews: PreviewProvider {
static var previews: some View {
ThirdCalcView()
}
}
I get this array of errors after the 'var Choice' declaration:
I annotated the closing braces to make sure I didn't miscount them.
The simple 'str1' multiline declaration at the beginning is fine so I think my declaration of an array is causing the problem.
I want to display a string based on the user's choice. Ultimately in the app, the user has to make three selections before the response is displayed so I am looking at using an array with three dimensions.
