                     display.text="\(newValue!)"
                 }
             }
-            userInMiddleOfTypingNumber=false
+            userIsTypingNumber=false
         }
     }
     

    @IBOutlet weak var history: UILabel!
    @IBOutlet weak var display: UILabel!
    
    var userInMiddleOfTypingNumber:Bool = false
    
    var brain = CalculatorBrain()
    
    @IBAction func appendDigit(sender: UIButton) {
        if let digit = sender.currentTitle{
            display.text = (userInMiddleOfTypingNumber ? display.text!+digit : digit)
            userInMiddleOfTypingNumber=true
        }
    }
    
    @IBAction func appendFloatingPoint() {
        if display.text!.rangeOfString(".")==nil{
            display.text=display.text!+"."
            userInMiddleOfTypingNumber=true
            historyValue = (historyValue ?? "") + "."
        }
    }
    
    @IBAction func undoDigit() {
        if let displayString = display.text, let historyString = historyValue{

            return history.text
        }
        set{
            clearHistoryIfNeeded()
            history.text = (newValue ?? "")
        }
    }
    
    func clearHistoryIfNeeded(){
        if history.text?.rangeOfString("=") != nil || history.text==nil{
            history.text = ""
        }
    }
}
