Tôi có hai giao thức giao tiếp với nhau. Chúng được định nghĩa trong cùng một tệp.Khai báo giao thức như @class
@protocol Protocol1 <NSObject>
-(void)setProtocolDelegate:(id<Protocol2>)delegate;
@end
@protocol Protocol2 <NSObject>
-(void)protocol:(UIViewController<Protocol1>*)anObject chosenElementAtIndex:(NSInteger)aIndex;
@end
Làm cách nào để khai báo giao thức trống Protocol2
chỉ để biết trình biên dịch được khai báo sau?
Nếu Protocol2
là lớp tôi muốn viết @class Protocol2;
trước đó.
@class Protocol2;
@protocol Protocol1 <NSObject>
-(void)setProtocolDelegate:(Protocol2*)delegate;
@end
@interface Protocol2 <NSObject>
-(void)protocol:(UIViewController<Protocol1>*)anObject chosenElementAtIndex:(NSInteger)aIndex;
@end
Cấu trúc tương tự cho giao thức là gì?
Tôi biết rằng nó không phải là '@ class'. Tôi đã sử dụng đoạn mã thứ hai để hiển thị tương tự với Lớp học, để làm cho câu hỏi rõ ràng hơn. Dù sao, cảm ơn sự giúp đỡ –