I am learning Swift and I am following a tutorial from Paul Hegarty on how to build a calculator using Polish Inverse Notation. The code looks like this:
@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()
}
}
The xCode compiler does not like the second instance of the performOperation function and reports that it has already been defined previously. The error it reports is:
Method 'performOperation' with Objective-C selector 'performOperation:' conflicts with previous declaration with the same Objective-C selector
What is wrong with my code?