Post

Replies

Boosts

Views

Activity

Reply to Using structs with TextField
class FinalBluePrint: ObservableObject {  @Published var currentGrade: Double = 5;  @Published var desiredGrade : Double = 0;  @Published var finalWeight : Double = 0;  var finalNeededGrade : Double {   let desiredGrade = self.desiredGrade;   let currentGrade = self.currentGrade;   let finalWeight = self.finalWeight;   let finalNeededGrade = (desiredGrade - currentGrade * (100 - finalWeight)) / finalWeight;   return finalNeededGrade  } } struct ContentView: View {  @StateObject var final = FinalBluePrint()  var body : some View {   NavigationView {    VStack {     TextField("Current Grade", value: $final.currentGrade, format: .number).keyboardType(.decimalPad);     TextField("Desired Grade", value: $final.desiredGrade, format: .number).keyboardType(.decimalPad);     TextField("Final Weight", value: $final.finalWeight, format: .number).keyboardType(.decimalPad);     Text(final.currentGrade, format: .number);     Text(final.finalNeededGrade, format: .number);    }   }  } }
Jun ’22