2
我有一個這樣的協議:向前聲明錯誤
#import <Foundation/Foundation.h>
@protocol Prot1 <NSObject>
@required
- (void)methodInProtocol;
@end
這是一個委託協議我想在這樣的類來存儲:
#import <Cocoa/Cocoa.h>
@class Prot1;
@interface Class1 : NSObject
@property (nonatomic, strong) Prot1 *delegate;
- (void)methodInClass;
@end
這個類的實現是像這樣:
#import "Class1.h"
#import "Prot1.h"
@implementation Class1
@synthesize delegate;
- (void)methodInClass {
[delegate methodInProt];
}
@end
當我打造這些作品的代碼,我得到以下錯誤:
Receiver type 'Prot1' for instance message is a forward declaration
這裏有什麼問題?我明白我必須通過@class爲協議進行前向聲明,並且我認爲我只需要在類實現中#import協議...是不是正確?