ios - fatal error: unexpectedly found nil while unwrapping an Optional value -
I'm trying to run this code but I get this error:
< P> Fatal error: Unlikely opening an optional value while opening zeroI do not know what it means or why am I receiving it Any hint?
Import UIKit Class ViewController: UIViewController {var last number: string = "@IBOutlet var answerField: UILabel @IBOutlet var operaterLabel: UILabel override func () {super.viewDidLoad () // Make an additional setup after loading the view, usually a nib from.} Override funk receive memory warning () {super.didReceiveMemoryWarning () / any resources that can be redone.} @Ibooting Funk Button Tap (Button: UIButton) {If answerField.text == "0" {answerField.text = theButton.titleLabel.text} and {answerField.text = answerField.text + TheButton.titleLabel.text}} @IBAction Func plusTapped (the Button: UIButton) {// Error talking about next line if operaterLabel.text == "{operaterLabel.text =" + "lastNumber = answerField Text answerField.text = "0"} and {enterTapped (zero) operaterLabel.text = "+"}} @IBAction func minusTapped (button: UIButton) {operaterLabel.text == "" {operaterLabel.text = "-" last Answer = answerField.text answerField.text = "0"} Else {enterTapped (zero) operaterLabel.text = "-"}} @IBAction func is empty (any object) {answerField.text = "0" operaterLabel.text = " "LastNumber =" "@IBAction func enterTapped (AnyObject?) {Var num1 = lastNumber.toInt () var num2 = answerField.text.toInt () if! Num1 || ! Num2 {showError () returns} var Reply = 0 if operaterLabel.text == "-" {var reply = num1! - Number 2! } Else if operaterLabel.text == "+" {var Reply = num1! + Num2! } Else {showError () Return} answerField.text = "\ (Answer)"} func showError () {println ("Ther was an error")}}
The error refers to the fact that you are reaching the parameters of the optional value when the optional value is set to zero (such as
answerField. Text when
answerField is zero), possibly one of your two
UILabels
if line
operaterLabel.text == "" is throwing exception, so your
operaterLabel is void that you have it up Nine interface builder is successfully linked to the label.
Comments
Post a Comment