Atomix
Atomix

Reputation: 13852

Protocol methods depending on each other

I have run into this weird situation where I have two protocols and both have methods with parameters that must conform to the other protocol. Sounds confusing, so heres some code:

@protocol ProtocolB <NSObject>
@required

-(void)methodB:(id<ProtocolA>)parameter;

@end



@protocol ProtocolA <NSObject>
@required

-(void)methodA:(id<ProtocolB>)parameter;

@end

The compiler says: "Cannot find protocol declaration for ...". Depending on which protocol comes first, it's either ProtocolA or ProtocolB. Putting them in different files didn't seem to solve this problem.

Any ideas how I can do this without a (major and possibly complicated) redesign?

Upvotes: 0

Views: 35

Answers (1)

Prajeet Shrestha
Prajeet Shrestha

Reputation: 8108

Forward declaration of protocol might do. Add @protocol ProtocolA; before ProtocolB

Upvotes: 5

Related Questions