Simple program to allow user to input weight in pounds or Kg and then print weight in Kg. The below code gives error: "Type '()' cannot conform to 'View'. Any help is greatly appreciated.
inline-code
import SwiftUI".
struct ContentView: View {
@State private var weight = 175.0
@State private var weightKg = 0.0
@State private var ifPounds: Bool = true
var body: some View {
VStack {
HStack {
Text("Select unit for weight:")
Toggle("", isOn: $ifPounds)
.labelsHidden()
.background(Color.green)
.clipShape(Capsule())
Text(ifPounds ? "Pounds" : "Kg")
.padding()
} // HStack
if (ifPounds == true) {
weightKg = weight/2.205
} else {
weightKg = weight
}
Text("Your weight is \(weightKg, specifier: "%.1f") ")
} //Vtack
} //Some View
} //Content View
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}