I recently came across the newest Stanford iOS Programming course given by Paul Hagerty. Yay!
I completed Lesson 01 with no problem. Now, I'm working on Lesson 02.
Having a problem around 42 minutes in when Paul shows how to overload the performOperation
function. The idea is to have two definitions: one for a two argument function (+, -, *, /) and the other for a single argument function, e.g. sqrt
.
It seems that since the lesson was posted, Swift has been updated/changed and this no longer works as shown in the lesson.
Does anyone know how to make it work? I've searched around and can't find anything useful.
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 ()
}
}
Thanks in advance!