Protocol declaration like @class

I have two protocols communicating with each other. They are defined in the same file.

@protocol Protocol1 <NSObject> -(void)setProtocolDelegate:(id<Protocol2>)delegate; @end @protocol Protocol2 <NSObject> -(void)protocol:(UIViewController<Protocol1>*)anObject chosenElementAtIndex:(NSInteger)aIndex; @end 

How to declare an empty Protocol2 Protocol2 to tell the compiler that it is declared later?

If Protocol2 was a class, I would write @class Protocol2; earlier.

 @class Protocol2; @protocol Protocol1 <NSObject> -(void)setProtocolDelegate:(Protocol2*)delegate; @end @interface Protocol2 <NSObject> -(void)protocol:(UIViewController<Protocol1>*)anObject chosenElementAtIndex:(NSInteger)aIndex; @end 

What is a similar design for protocols?

+7
source share
2 answers

Use @protocol to declare protocols:

 @protocol Protocol2; @protocol Protocol1 <NSObject> -(void)setProtocolDelegate:(id<Protocol2>)delegate; @end @protocol Protocol2 <NSObject> -(void)protocol:(UIViewController<Protocol1>*)anObject chosenElementAtIndex:(NSInteger)aIndex; @end 
+10
source

The problem with yours is that you have a protocol with an ad with the @class keyword. It should be @protocol.

+1
source

All Articles