When entering for the the value for the Tip and the PriceTxt I want to check if it's empty first and return the "Add numbers" if it is but I get the error
Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var PriceTxt: UITextField!
@IBOutlet weak var Tip: UITextField!
@IBOutlet weak var totalFinal: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
totalFinal.text = ""
}
@IBAction func Calcualte(_ sender: Any) {
if (PriceTxt.text!) == nil || (Tip.text!) == nil
{
totalFinal.text = "Add numbers"
}
else {
let price = Double(PriceTxt.text!)!
let tipPer = Double(Tip.text!)!
let TipMult = price * (tipPer/100)
let TipFinal = Double((round(100*TipMult)/100) + price)
totalFinal.text = "$\(TipFinal)"
}
}
}