19
votes

I am using code that worked with Xcode 7 Beta 2. Just got Beta 3 and now I'm getting this problem that seems like an Xcode bug?

For one of my public classes...

override public func observeValueForKeyPath...

Method does not override any method from its superclass

So I take out the "override":

public func observeValueForKeyPath

Method conflicts with method from superclass NSObject with the same Objective-C selector

ha! I was lied to by the first error. Won't compile either way. Any help please?

2
This may sound rudimentary, but have you cleaned your build folder (cmd-shift-k)?Oxcug
That didn't help, but matt's answer (change NSObject to String) fixed it.36 By Design

2 Answers

21
votes

Change [NSObject:AnyObject] in the declaration to [String:AnyObject].

31
votes

If the definition is copied from NSKeyValueObserving.h, your override would look like the below:

override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
    // ...
}

Note: For methods like this one, you could usually press Cmd+Shift+O and go straight to Open Quickly... pop-up field where any definition could be copy/pasted and Xcode will search for it within the project/SDK. Watch for iOS scope in this case.