gpt4 book ai didi

swift - 在 Swift 中重写函数

转载 作者:搜寻专家 更新时间:2023-11-01 06:08:55 26 4
gpt4 key购买 nike

<分区>

我正在学习 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()

}
}

xCode 编译器不喜欢 performOperation 函数的第二个实例,并报告它之前已经定义过。它报告的错误是:

带有 Objective-C 选择器“performOperation:”的方法“performOperation”与之前使用相同 Objective-C 选择器的声明冲突

我的代码有什么问题?

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com