views:

234

answers:

3

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
A: 

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)

pgb
Yeah, I've #imported the protocols in the subclass's header file. It seems especially odd to me thad it only complains that one of the protocols supposedly isn't conformed to. It's as if it's ignoring the delegate's declaration.
Cinder6
A: 

What happens if you break the protocols apart into separate files, then import them both into your NSWindowController class?

Tim
+1  A: 

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.

AlBlue
This worked. I also found another way by making the delegate a property and specifying the adopted protocols for the id that way.
Cinder6