Objective c 声明类似@class的协议

Objective c 声明类似@class的协议,objective-c,Objective C,我有两个相互通信的协议。它们在同一个文件中定义 @protocol Protocol1 <NSObject> -(void)setProtocolDelegate:(id<Protocol2>)delegate; @end @protocol Protocol2 <NSObject> -(void)protocol:(UIViewController<Protocol1>*)anObject chosenElementAtIndex:(NSInt

我有两个相互通信的协议。它们在同一个文件中定义

@protocol Protocol1 <NSObject>
-(void)setProtocolDelegate:(id<Protocol2>)delegate;
@end

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

协议的类似结构是什么?

使用@protocol进行协议转发声明:

@protocol Protocol2;
@protocol Protocol1 <NSObject>
-(void)setProtocolDelegate:(id<Protocol2>)delegate;
@end

@protocol Protocol2 <NSObject>
-(void)protocol:(UIViewController<Protocol1>*)anObject chosenElementAtIndex:(NSInteger)aIndex;
@end
@协议协议2;
@协议协议1
-(void)委托人:(id)委托人;
@结束
@协议协议2
-(无效)协议:(UIViewController*)对象选择元素索引:(NSInteger)aIndex;
@结束

您的问题在于,您已使用@class关键字转发声明的协议。
它应该是@protocol。

我知道它不应该是
@class
。我使用第二个片段来表示与类的类比,以使问题更清楚。不管怎样,谢谢你的帮助
@protocol Protocol2;
@protocol Protocol1 <NSObject>
-(void)setProtocolDelegate:(id<Protocol2>)delegate;
@end

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