The error "Binary operator + cannot be applied to operands of type Binding<Double?> and Double" occurs on line 24 (line 22 if looking at original post) inside the function. I've tried making the function in other parts of the code, but then I start to get errors saying that variables aren't in the scope.
I'm not looking for someone to just type out the code and say "Here is the fix". If you can point me in the right direction, I've got no problem going through tutorials and learning, but at this point, I'm at a loss. I've already completed a couple of SwiftUI and Swift Storyboard courses on Udemy and had a good enough understanding of the basics of Swift language to get this far.
This is the code in BOIEquations.swift:
import SwiftUI
class BOIEquations: ObservableObject {
static var shared = BOIEquations()
var sublotSampTons: Double? = 0.0
let randomNumber = Double.random(in: 0.001..<1)
var ranSampTons: Double {
let storedRandomNumber = randomNumber
let ranSampTonnage = storedRandomNumber * 1000
return ranSampTonnage
}
}
This is the full code from the BaseOGIntView.swift:
struct BaseOGIntView: View {
@StateObject var equation = BOIEquations()
var sublotSampTons = BOIEquations.shared.sublotSampTons
var body: some View {
// Display Random Number
VStack {
let storedRanSampTons = BOIEquations.shared.ranSampTons
Form {
Section{
Text("Random Number: \(BOIEquations.shared.randomNumber, specifier: "%.3f")")
}
Section {
Text("Sublot Tons: \(storedRanSampTons, specifier: "%.0f")")
TextField("Sublot Tons", value: $equation.sublotSampTons, formatter: NumberFormatter())
Button(action: {
func sublotTonnage(_ number: Double) -> Double {
var number = $equation.sublotSampTons + storedRanSampTons
return number
}
}) {
Text("Generate Random Sample")
}
}
Text("Random Sample Tonnage: \(sublotTonnage) ")
}
}
}
}
struct BaseOGIntView_Previews: PreviewProvider {
static var previews: some View {
BaseOGIntView()
}
}
Thanks again for any help you might give.