I've been looking on this site for an answer to my question but no matter what I do my compiler still gives me the following error:
fatal error: unexpectedly found nil while unwrapping an Optional value
I don't know what is causing this seeing as I wrapped up all my code in an if statement
to ensure that if the value submitted is nil it would print a message.
Here is the code:
@IBOutlet var textField: UITextField!
@IBOutlet var label4: UILabel!
@IBAction func buttonTapped(_ sender: Any) {
if textField.text != nil {
let textFieldInt: Int? = Int(textField.text!)
let convert = textFieldInt! * 7
label4.text = String(convert)
}
else {
label4.text = "Please enter a number!"
}
}
I've searched through similar questions and have understood a small amount about what is causing this error but I have yet to find a solution.
Could someone please help me?
I am using Xcode8 with the latest version of Swift.