簡體   English   中英

協議錯誤。 找不到協議聲明

[英]Protocol error. Cannot find protocol declaration

我們遇到錯誤:找不到“ 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對象。 在OtherSystem中,使用ScoreSystem和OtherSystem2等。我們要為所有系統創建通用協議。

您的兩個頭文件之間有一個循環依賴關系(每個都導入另一個)。 不要在Protocol.h中導入ScoreSystem.h@class正向聲明就足夠了。 您的其他兩個進口貨物也是如此。

通常,我避免在其他類頭文件中包含類頭文件-我只在各處使用@class並將頭文件導入實現文件中。

礦山問題通過簡單的導入語句解決

#import "ProtocolContainingFile.h"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM