Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error with: override public func observeValueForKeyPath

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?

like image 616
36 By Design Avatar asked Jul 09 '15 04:07

36 By Design


2 Answers

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.

like image 145
Yevhen Dubinin Avatar answered Oct 18 '22 19:10

Yevhen Dubinin


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

like image 27
matt Avatar answered Oct 18 '22 21:10

matt