你能帮我理解代表和协议吗:
在这段代码中:
@protocol FirstViewControllerDelegate; @interface FirstViewController : UIVIewController { … id<FirstViewControllerDelegate> delegate; } @property (assign) id <FirstViewControllerDelegate> delegate;
感谢您的回答
保
答案 0 :(得分:1)
@protocol FirstViewControllerDelegate;
该格式的是前瞻性声明。它告诉编译器FirstViewControllerDelegate
是一个有效的协议,将在稍后定义(有时在同一个.h文件中进一步向下)。它是必需的,因为没有它,编译器会在看到行
id<FirstViewControllerDelegate>
因为它没有看到它的声明。
实际协议可以定义为
@protocol FirstViewControllerDelegate
{
@required
- (void)myImportantDelegateMethod;
}