I have a simple protocol with a property:
@protocol StopsSource <NSObject>
@property (retain,readonly) NSArray * stops;
@end
I'm adding a key-value observer elsewhere to listen to changes to the "stops" property:
id<StopsSource> source = ...
[source addObserver:self
forKeyPath:@"stops"
options:NSKeyValueObservingOptionNew
context:nil];
Code works as expected in that I get observeValueForKeyPath events when the "stops" property is changed. The real annoyance is a compiler warning on the addObserver call:
warning: '-addObserver:forKeyPath:options:context:' not found in protocol(s)
The 'addObserver' method is defined in a category to NSObject:
@interface NSObject(NSKeyValueObserverRegistration)
Is there any way to get XCode to drop this warning? It's my understanding that protocols can't adopt categories, so I'm not sure how to bring the NSKeyValueObserverRegistration methods into my protocol, short of copying the declarations into the protocol itself, which seems like a hack.
I know this is kind of a trivial problem, in that it's just a compiler warning, but I'm interested to know if there is a "right" way to address this.