I'm following the Stanford Videos for iOS development and I am using Xcode 7 with Swift 2.
I wrote the code from the video line by line, however I keep getting an error.
import UIKit
class ViewController: UIViewController
{
@IBOutlet weak var display: UILabel!
var userIsTyping = false
@IBAction func AppendDigit(sender: UIButton) {
let digit = sender.currentTitle!
if userIsTyping {
display.text = display.text! + digit
} else {
display.text = digit
userIsTyping = true
}
}
var operandStack = Array<Double>()
@IBAction func enter() {
userIsTyping = false
operandStack.append(displayValue)
}
var displayValue: Double {
get{
return NSNumberFormatter().numberFromString(display.text!)!.doubleValue
}
set (newValue){
display.text = "\(newValue)"
userIsTyping = false
}
}
}
At the line where I return
NumberFormatter().numberFromString(display.text!)!.doubleValue
I get an error of
Thread 1: EXC_BAD_INSTRUCTION(code=EXC_1386_INVOP,subcode=0x0)
displayis nil or contains not-number-string.