Iphone 协议错误。找不到协议声明

Iphone 协议错误。找不到协议声明,iphone,objective-c,protocols,Iphone,Objective C,Protocols,我们有错误:找不到'classwhichusemainsene'的协议声明[3] 我们创建了以下文件: 方案h #import "ScoreSystem.h" #import "OtherSystem" #import "OtherSystem2" @class ScoreSystem; @protocol SceneDelegate <NSObject> @property (nonatomic, readonly,retain) ScoreSystem* score; @pr

我们有错误:找不到'classwhichusemainsene'的协议声明[3]

我们创建了以下文件: 方案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”
#导入“其他系统”
#导入“其他系统2”
@班级计分制;
@协议场景LEGATE
@属性(非原子、只读、保留)ScoreSystem*分数;
@属性(非原子、只读、保留)OtherSystem*系统;
@属性(非原子、只读、保留)OtherSystem2*system2;
@结束
并在记分系统中使用

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

@interface ScoreSystem: NSObject <SceneDelegate> 
{
OtherSystem* system;
OtherSystem2* system2;
}
#导入“Protocol.h”
#导入“其他系统”
#导入“其他系统2”
@接口系统:NSObject
{
其他系统*系统;
其他系统2*系统2;
}
在ScoreSystem中,我们只希望使用OtherSystem和OtherSystem2对象。在OtherSystem中使用ScoreSystem和OtherSystem2等。
我们希望为所有系统创建通用协议。

您的两个头文件之间存在循环依赖关系(每个头文件导入另一个头文件)。不要在Protocol.h中导入
ScoreSystem.h
@class
转发声明就足够了。这同样适用于其他两种进口产品


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

您的两个头文件之间存在循环依赖关系(每个头文件导入另一个头文件)。不要在Protocol.h中导入
ScoreSystem.h
@class
转发声明就足够了。这同样适用于其他两种进口产品


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

我的问题通过简单的导入语句解决了

#import "ProtocolContainingFile.h"

用简单的导入语句解决矿山问题

#import "ProtocolContainingFile.h"

不过,为了清楚起见,您可能仍然希望导入实现文件中的头。@Chuck:很好。我将对答案进行修改,使其更清楚,不过,您可能仍然希望在实现文件中导入头。@Chuck:很好。我要修改答案