I'm trying to figure out this
unexpectedly found nil while unwrapping an Optional value
Code works fine until I try computeFahreheit Button with an empty UITextField.
Tons of stuff on this subject, I just can't figure it out for this code.
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var inputCelsius: UITextField!
@IBOutlet weak var outputFahrenheit: UILabel!
@IBAction func computeFahreheit(_ sender: Any) {
var convertedNumber = Int(inputCelsius.text!)!
convertedNumber = convertedNumber * 9/5 + 32
outputFahrenheit.text = "\(convertedNumber)F"
if (inputCelsius.text == nil) {
outputFahrenheit.text = "Enter Celsius"
}else{
outputFahrenheit.text = "\(convertedNumber)"
}
Any help would be appreciated, thank you.