I'm designing an app for the company I work for that uses a basic y=mx+c (or y=mx+b if you're from the US) to take 2 calibrated values and 2 input values to output scale and offset values. The app takes a users input from a total of 4 text fields, and then uses a few formulas to output into a text view. My problem is that the input values need to be 'Doubles' for use in the formulas (Divisor, m_FinalScale, m_FinalOffset) whereas the values that the user inputs are 'Strings?' because they are from a text field. How could I go about unwrapping and converting those optional strings to then use?
override func viewDidLoad() {
super.viewDidLoad()
Cal1Field.delegate = self
Cal2Field.delegate = self
Input1Field.delegate = self
Input2Field.delegate = self
}
//Actions
@IBAction func CalibrateTapped(_ sender: Any) {
var Divisor = 0.0, m_FinalScale = 0.0, m_FinalOffset = 0.0
// this is what the formulas are
Divisor = Input2Field.text - Input1Field.text
m_FinalScale = (Cal2Field.text - Cal1Field.text)/Divisor
m_FinalOffset = Cal1Field.text - (m_FinalScale*Input1Field.text)
}