Error in Swift 2: Overloading a function

Hi there!


I am a novice to Swift and Xcode, but know C++.


I tried to mimick the code in a Stanford University course for iOS 8 App development (2014-15) using Xcode 7 and swift 2 for the calculator example.


In his lecture 2 video on https://www.youtube.com/watch?v=QLJtT7eSykg,the lecturer suggested over loading a function like this (and I think they were using Xcode 6 and an earlier Swift standard):


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()

}

}


However, the compiler seems to have problem with this overloading attempt, and the error is:


/Users/.../Calculator/ViewController.swift:50:10: Method 'performOperation' with Objective-C selector 'performOperation:' conflicts with previous declaration with the same Objective-C selector


The error seems to be only on the function's second definition line (indicated by forward slashes). The rest of the code has no problem.


How can I work around this error?

Thanks in advance ... moodamultani

First of all:

a Stanford University course for iOS 8 App development (2014-15)

It's too old to work with Swift 2, and you should better find a more up-to-date tutorial and example code, or else you'll need to post huge amount of questions on the forums...


And to know the reason about why such sort of overloading is not allowed, you need to learn a little more about Objective-C.

Skipping that step, try adding `@nonobjc` before each `func`.

Error in Swift 2: Overloading a function
 
 
Q