@IBAction func operate(sender: UIButton) {
if let operation = sender.currentTitle {
if let result = brain.performOperation(operation) {
displayValue = result
}
else {
displayValue = 0.0
}
}
}
Run Code Online (Sandbox Code Playgroud)
我是编码的新手,所以请原谅我的编码格式和其他不一致之处.我一直在试用iOS 8介绍斯坦福大学教授的快速编程,我遇到了修改后的计算器问题.
我得到三个错误.第一个是快速编译警告 - 在
if let result = brain.performOperation(operation)
Run Code Online (Sandbox Code Playgroud)
它说
常量'result'推断为type()可能是意外的.
它给了我这样做的建议----
if let result: () = brain.performOperation(operation)
Run Code Online (Sandbox Code Playgroud)
另外两个错误是
如果让结果行,条件绑定中的绑定值必须是可选类型
无法在"displayValue = result"处将type()的值赋值为Double
如果有人需要有关代码的更多信息,这是github链接.
提前致谢.