问题
I just started coding with Swift and I try to build a calculator. When I launch the simulator and I click the button '1' of the calculator it calls Tap0 function. I encountered the following issue: Can't unwrap Optional.None.
import UIKit
class ViewController: UIViewController {
@IBOutlet var display:UITextField
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
@IBAction func Tap0(sender:AnyObject){AddNumber("0")}
func AddNumber(x:String){
self.display.text="" //ERROR (Can't unwrap Optional.None)
println(self.display.text)
}
}
How I can solve it?
回答1:
As what rdelmar suggested, to solve the error, connect display to the UITextField in StoryBoard:

来源:https://stackoverflow.com/questions/24562077/uitextfield-cant-unwrap-optional-none