19

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?

pkamb
  • 33,281
  • 23
  • 160
  • 191
36 By Design
  • 3,203
  • 3
  • 18
  • 18

2 Answers2

31

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.

pkamb
  • 33,281
  • 23
  • 160
  • 191
Yevhen Dubinin
  • 4,657
  • 3
  • 34
  • 57
21

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

matt
  • 515,959
  • 87
  • 875
  • 1,141