-4
我遇到此代碼並不確定它如何執行諸如(*,+, - ,%)等操作。有人可以解釋它是如何知道例如必須添加這兩個數字嗎?快速幫助,請解釋此代碼的工作原理
var operandStack = Array<Double>()
switch operation {
case "×": performOperation { $0 * $1 }
case "+": performOperation { $0 + $1 }
func performOperation(operation: (Double, Double)->Double)
{
displayValue=operation(operandStack.removeLast(),
operandStack.removeLast())
}
var displayValue: Double
{
set {
display.text = "\(newValue)"
}
get {
return NSNumberFormatter().numberFromString
(display.text!)!.doubleValue
}
}