Reputation: 1
I keep getting this error when I run my program in Xcode:
fatal error: unexpectedly found nil while unwrapping an Optional value
Here's my code:
@IBOutlet var textFielD: UITextField!
@IBOutlet var message: UILabel!
@IBAction func guessButton(sender: AnyObject) {
var numberOfFingers = arc4random() % 6
println(numberOfFingers)
var numberOfFingersString = String(numberOfFingers)
if (numberOfFingersString == textFielD.text!) {
message.text = "You got it right!"
} else {
message.text = "Nope! I was holding up \(numberOfFingers) fingers. Try again!"
}
I am working in Xcode 6.1.1 (the most recent version) on an iMac running Yosemite.
Thank you for the help.
Upvotes: 0
Views: 2539
Reputation: 70155
Either textFielD
(note 'spelling' error) or message
is not linked in Interface Builder. Check that all outlets are bound. IBOutlets
are always declared as implicitly unwrapped optionals - you need to bind them in Interface Builder or in viewDidLoad
(or a similarly early method).
Upvotes: 3