Hello, I come across a problem I cannot solve, also the stack overflow results don’t show the solution. I also searched this forum.
I have to Integer variables which are in a Textfield and want to make a mathematic addition and present it as a variable in a Text. But the Initialization does not work correctly
That’s what I want to achieve
var var1 = 1
var var2 = 2
var result = (var1 * 75) + (var2 * 85)
That’s my solution but it does not work unfortunately
Thanks for reading
import SwiftUI
class Crew {
var var1:Int = 1
var var2:Int = 2
var result:Int = (var1 * 75) + (var2 *85)init(var1: Int, var2: Int, result: Int) { _var1 = State(initialValue: 1) _var2 = State(initialValue: 2) _result = State(initialValue: 3) }
}
struct DOWView: View { @State var crew = Crew() var body: some View { VStack { TextField("#", value: $crew.var1, format: .number) TextField("#", value: $crew.var2, format: .number) Text("\(crew.result)") } struct DOWView_Previews: PreviewProvider { static var previews: some View { DOWView() } }