import SwiftUI
struct ContentView: View {
let inputOptions = ["Celcius","Fahrenheit","Kelvin"]
let outputOptions = ["Celcius","Fahrenheit","Kelvin"]
@State private var selectedInput = "Celcius"
@State private var inputValue : Int = 0
@State private var selectedOutput = "Fahrenheit"
let inputCelcius = inputOptions[0] // THIS IS WHERE ERROR POPS UP
var body: some View {
NavigationView{
Form{
Section{
Picker("Select input", selection: $selectedInput) {
ForEach(inputOptions, id: \.self) {
Text($0)
}
}
TextField("Amount", value: $inputValue, format: .number)
} header : {
Text("Select conversion value and input value")
}
Section{
Picker("Select output", selection: $selectedOutput) {
ForEach(outputOptions, id: \.self) {
Text($0)
}
}
} header : {
Text("Select conversion value and output value")
}
}
.navigationTitle("UnitConversion")
.navigationBarTitleDisplayMode(.inline)
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
All i'm trying to do is create variables containing individual values of my inputOptions Array. Keep seeing "Cannot use instance member 'inputOptions' within property initializer; property initializers run before 'self' is available". I understand this issue most likely has a basic fix, but I can't seem to find it. I'm new to Swift, and programming in general.