1 functional-programming swift
我正在学习Swift,我正在学习Paul Hegarty关于如何使用波兰语反向表示法构建计算器的教程.代码如下所示:
@IBAction func operate(sender: UIButton) {
let operation = sender.currentTitle!
if userIsEnteringData{
enter()
}
switch operation {
case "×": performOperation {$0 * $1}
case "÷": performOperation {$1 / $0}
case "+": performOperation {$0 + $1}
case "?": performOperation {$1 - $0}
case "?": performOperation {sqrt($0)}
case "sin": performOperation {sin($0)}
case "cos": performOperation {cos($0)}
case "?": performOperation{$0 * M_PI}
default: break
}
}
func performOperation (operation : ( Double, Double ) -> Double){
if operandStack.count >= 2 {
displayValue = operation(operandStack.removeLast(), operandStack.removeLast())
enter()
}
}
func performOperation (operation : Double -> Double){
if operandStack.count >= 1 {
displayValue = operation(operandStack.removeLast())
enter()
}
}
Run Code Online (Sandbox Code Playgroud)
xCode编译器不喜欢performOperation函数的第二个实例,并报告它之前已经定义过.它报告的错误是:
Method 'performOperation' with Objective-C selector 'performOperation:' conflicts with previous declaration with the same Objective-C selector
我的代码出了什么问题?
| 归档时间: |
|
| 查看次数: |
1743 次 |
| 最近记录: |