Compiler error: Method with Objective-C selector conflicts with previous declaration with the same Objective-C selector

I am starting to learn Swift, and have been following the very good Stanford University video lectures on YouTube. Here is a link if you are interested or it helps (although it isn’t required to understand my problem):

Developing iOS 8 Apps with Swift – 2. More Xcode and Swift, MVC

While following the lectures I got to a point where (as far as I could tell) my code was identical to the code in the video but on my system I got a compiler error. After a lot of trial and error I have managed to reduce my code to two examples, one of which generates an error, the other or which doesn’t, but I have no idea what is actually causing the error or how to resolve it.

The code which creates the error is:

import UIKit

class BugViewController: UIViewController
{
    func perform(operation: (Double) -> Double) {
    }

    func perform(operation: (Double, Double) -> Double) {
    }
}

This creates the following compiler error:

Method ‘perform’ with Objective-C selector ‘perform: ‘ conflicts with previous declaration with the same Objective-C selector

By simply removing the sub-classing of UIViewController the code compiles:

import UIKit

class BugViewController
{
    func perform(operation: (Double) -> Double) {
    }

    func perform(operation: (Double, Double) -> Double) {
    }
}

Some other information which may or may not be relevant:

  • I have recently upgraded to Yosemite.
  • When I installed Xcode, I ended up with a Beta version (Version 6.3 (6D543q)) because (if I remember correctly) this was the version I needed to run on my version of OS X.

I am half hoping this is a bug in the compiler because otherwise this doesn’t make any sense to me. Any help very gratefully received!

6 Answers
6

Leave a Comment