Note that there are some explanatory texts on larger screens.

plurals
  1. POWarning: MyClass:NSObject does not implement key value observing? How can that be?
    text
    copied!<p>I just recently resumed work on a Cocoa project that I left a few months ago. Cocoa is a strange beast if you have not been using it for a while.</p> <p>Anyway, at some point the compiler started dropping warnings:</p> <blockquote> <p>Incomplete implementation of class 'MyClass'<br> Method definition for '-addObserver:forKeyPath:options:context' not found<br> Method definition for '-removeObserver:forKeyPath:' not found<br> Class 'MyClass' does not fully implement the 'MyZoomScrollViewDataSource' protocol </p> </blockquote> <p>But <code>MyClass</code> is derived from <code>NSObject</code>, which does in fact implement <code>-addObserver:forKeyPath:</code> and <code>-removeObserver:forKeyPath:context:</code>.</p> <p>The protocol looks like this:</p> <pre><code>@protocol MyZoomScrollViewDataSource // The range of Data that should be shown. This corresponds to the horizontal // zoom and the scroll value of self. @property FRange selectionRange; // Also, make sure the dataSource is KVO compliant - (void)addObserver:(NSObject *)anObserver forKeyPath:(NSString *)keyPath options:(NSKeyValueObservingOptions)options context:(void *)context; - (void)removeObserver:(NSObject *)anObserver forKeyPath:(NSString *)keyPath; @end </code></pre> <p>The class looks like this:</p> <pre><code>@interface MyClass : NSObject &lt;MyZoomScrollViewDataSource&gt; { IBOutlet Outlets... variables... } @properties... (IBAction)actions... - methods... @end </code></pre> <p>I guess my Cocoa skills are in deep need for a refresh. But still, these methods should be inherited from <code>NSObject</code>, so how can <code>MyClass</code> not implement these methods?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload