Can anyone help me understand why the first line of code generates a runtime EXC_BAD_INSTRUCTION error and the second line does not?
let actualHandicap = Float(exactHandicap.text ?? "0.0")
let shotsGiven = Int(numShotsGiven.text ?? "0")
The purpose of these two lines of code are to initialise the float actualhandicap and the int shotsGiven. I want them both to be set to zero should the two UITextField instances (exactHandicap and numShotsGiven be nil.
This code is an excerpt from a segue unwind method I've built based on a tutorial from Apple.
The app compiles and runs but will always crash when the unwind method is called. The stdout displays fatal error: unexpectedly found nil while unwrapping an Optional value
The contents of the local variables in the debugger indicate that actualHandicap has not been set to zero as expected, but shotsGiven has.
As a Swift newbie, I expect I'm missing something fundamental with how I'm using the Int() and Float() functions to cast the strings to zero, but I'm unable to see what's going wrong.
Any help gratefully received.