I am writing an app for a fencing company where the user can specify how many meters of fence they require and it will calculate the number of panels, feet and clamps needed for that meterage, I also have 2 fields where they can add additional clamps and additional feet to their order when they do this it automatically updates the values it calculated before to include the extras.
This works fine so long as the text field always has a number in it, for example, if you enter 30m into the first box the app would work out that you need 31 feet, if I put 3 additional feet on the order it says 34 feet, if I then change my mind and delete the contents of the extra feet field the app crashes due to finding nil while unwrapping an optional value
, is there a way I can get around this?
I have the following code:
@IBAction func AdditionalFeetField(sender: AnyObject) {
if AdditionalFeetField.text != nil {
let AdditionalFeetValue1 = Double(PanelQtyField.text!);
let AdditionsFeetValue2 = Double(AdditionalFeetField.text!);
let AdditionalFeetResult = (AdditionalFeetValue1! + AdditionsFeetValue2!) + 1
self.FeetQtyLabel.text = "\(AdditionalFeetResult)"
}
}
`