Reputation: 566
Alright, I have two protocols in the same header file, let's call them Protocol1 and Protocol2. I have a main app controller that conforms to both protocols, and an NSWindowController subclass that has the following member:
id <Protocol1, Protocol2> delegate;
I'm getting a warning at the end of my NSWindowController subclass implementation that "type id does not conform to Protocol2". But, as shown, the delegate must conform to both protocols, which it does.
Furthermore, the application works perfectly. Is there some other way to do this? I suppose I could just fold the two protocols in together, but that would hurt the modularity of the program.
EDIT:
Here are the two protocols. As this is more of a test scenario, they're short.
@protocol TPTBController <NSObject>
-(void)sendGrowlMessage:(NSString *)message title:(NSString *)title;
@end
@protocol AddPower <NSObject>
-(void)addPower:(NSArray *)array;
-(void)setCanAddPower:(BOOL)can;
@end
Upvotes: 3
Views: 1345
Reputation: 24060
The language spec isn't clear if the id-with-protocols actually supports a protocol list or not. Protocols can extend protocol lists, but it's not clear if that syntax supports it or not.
You could create a combined protocol:
@protocol AddPowerAndTPTBController <AddPower, TPTBController>
@end
...
id <AddPowerAndTPTBController> delegate;
Whilst not elegant, it would work; but it would require your delegate class to conform to the AddPoewrAndTPTBController as well, not just the two individually.
Upvotes: 3
Reputation: 60150
What happens if you break the protocols apart into separate files, then import them both into your NSWindowController
class?
Upvotes: 0
Reputation: 25011
Are you importing the protocols on your NSWindowController
subclass?
That the application works points me in that direction. It seems that when doing the static checking, the compiler can't figure that your class conforms to the protocols, while when actually dispatching messages it's succeeding (and that's why the application works as expected)
Upvotes: 1