2012-03-27 173 views
0

我们有错误:无法找到协议声明 'ClassWhichUseMainScene'[3]协议错误。找不到协议声明

我们创建的文件: Protocol.h

#import "ScoreSystem.h" 
#import "OtherSystem" 
#import "OtherSystem2" 

@class ScoreSystem; 

@protocol SceneDelegate <NSObject> 
@property (nonatomic, readonly,retain) ScoreSystem* score; 
@property (nonatomic, readonly,retain) OtherSystem* system; 
@property (nonatomic, readonly,retain) OtherSystem2* system2; 

@end 

而且在ScoreSystem.h

#import "Protocol.h" 
#import "OtherSystem" 
#import "OtherSystem2" 

@interface ScoreSystem: NSObject <SceneDelegate> 
{ 
OtherSystem* system; 
OtherSystem2* system2; 
} 
使用

在ScoreSystem中,我们只需要使用OtherSystem和OtherSystem2对象。在其他系统中使用ScoreSystem和OtherSystem2等。 我们希望为所有系统创建通用协议。

回答

4

你有两个头文件(每个都导入另一个)之间的循环依赖关系。在Protocol.h中不要导入ScoreSystem.h@class前向声明就足够了。您的其他两个进口也是如此。

作为一般规则,我避免在其他类头文件中包含类头文件 - 我只是在所有地方使用@class并将头文件导入到实现文件中。

+0

解决地雷问题需要明确的是,虽然,你可能仍然要导入的头在实现文件。 – Chuck 2012-03-27 08:32:10

+0

@收集:很好。我要修改答案 – JeremyP 2012-03-27 08:33:22

0

用简单的import语句

#import "ProtocolContainingFile.h"