I'm trying to create a conversion from Fahrenheit to Celsius, which requires me to call on the amount the user chose. Here's what I have so far
@State private var temperatureChoices = ["Celsius", "Fahrenheit"]
@State private var startTemp = "Celsius"
@State private var endTemp = "Fahrenheit"
@State private var startAmount = 0.0
@State private var endAmount = 0.0
let fToC = {
return (5/9) * (startAmount - 32)
}
var body: some view{
I've tried doing it without the closure, but that doesn't work either. I've tried doing it inside of the body, but that doesn't work. What am I doing wrong here? How do I instantiate a variable using another variable?
fToCchange it fromlettovarand remove the=.@Statefor every option. I would expect 1 state property for type of temperature (e.g.@State private var selectedType: String // "Celsius" or "Fahrenheit") and one@Statefor current selection (e.g.@State private var amount: Double // whatever user chose, inselectedTypeunits). Also consider usingenumto express "Celsius", "Fahrenheit"var fToC: Double { (5/9) * (startAmount - 32) }