我正在关注斯坦福iOS 8讲座,我相信我已经成功添加了#34; Clear"应用程序的功能,但我不知道我是否正确地做到了。我的代码如下:
控制器
class ViewController: UIViewController
.
.
.
// Linked to the "C" button in the Storyboard
@IBAction func clear()
{
userIsInTheMiddleOfTypingANumber = false
brain.clear()
displayValue = 0
.
.
.
模型
class CalculatorBrain
.
.
.
func evaluate() -> Double?
{
let (result, remainder) = evaluate(opStack)
println("\(opStack) = \(result) with \(remainder) left over")
return result
}
func clear()
{
opStack = [Op]()
evaluate()
}
.
.
.
我的日志输出是
[8.0] = Optional(8.0) with [] left over
[8.0, 9.0] = Optional(9.0) with [8.0] left over
[8.0, 9.0, ×] = Optional(72.0) with [] left over
[8.0, 9.0, ×, 2.0] = Optional(2.0) with [8.0, 9.0, ×] left over
[8.0, 9.0, ×, 2.0, −] = Optional(70.0) with [] left over
[8.0, 9.0, ×, 2.0, −, 5.0] = Optional(5.0) with [8.0, 9.0, ×, 2.0, −] left over
[8.0, 9.0, ×, 2.0, −, 5.0, ÷] = Optional(14.0) with [] left over
[] = nil with [] left over
我很确定日志输出中的最后一行是正确的。基本上我只是希望有更多iOS / MVC经验的人可以告诉我是否实现了" Clear"功能正确。如果我没有,我怎么能修复我的代码?
先谢谢你
答案 0 :(得分:0)
我做了像这样的明确功能
@IBAction func clear(sender: UIButton) {
AudioServicesPlaySystemSound(audioSound)
arrayDigit.removeAll()
arrayOp.removeAll()
display.text = "0" //displayStack() // remove !
displayValue = 0
equal()
}