Hi Team,
I am building and playing around with a simple Watch App using SwiftUI.
Looks like I have to use TextField as an input, it’s then a String.
The user then adds a value as a number int or double, but as it’s a textfield it is a String.
I need to work out a way to take the two inputs and make a calculation.
See code below…
I wish to take the litresValue String and change it to a double being litresValueNumber Double and then make a calculation with the other input mixRatioValue and change it to a double.
Any suggestions ?
Cheers. Help !
Craig.
Code below.
//
// ContentView.swift
// FuelMix iWatch WatchKit Extension
//
// Created by Craig Karen Shine on 29/12/19.
// Copyright © 2019 Craig Karen Shine. All rights reserved.
//
import SwiftUI
struct ContentView: View {
@State private var litresValue: String = “1”
@State private var mixRatioValue: String = “50”
@State private var litreValueNumber: Double = 0.0
@State private var mixRatioValueNumber: Double = 0.0
var body: some View {
ScrollView{
VStack {
Image("FuelMix2png")
.resizable()
.frame(width: 60.0, height: 60.0)
Text("FuelMix")
.padding(.top, -11.0)
}
VStack{
HStack {
Text("Litres:")
TextField("", text: $litresValue)
}
HStack {
Text("Mix\rRatio:1 ")
TextField("", text: $mixRatioValue)
}
NavigationLink(destination: DisplayValue()) {
Text("Go!")
.multilineTextAlignment(.center)
.accentColor(/*@START_MENU_TOKEN@*/.white/*@END_MENU_TOKEN@*/)
}
.background(/*@START_MENU_TOKEN@*/Color.blue/*@END_MENU_TOKEN@*/)
.clipShape(/*@START_MENU_TOKEN@*/Circle()/*@END_MENU_TOKEN@*/)
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}