1

We have error: cannot find protocol declaration for 'ClassWhichUseMainScene' [3]

We created file: 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

And use in ScoreSystem.h

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

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

In ScoreSystem we want use just OtherSystem and OtherSystem2 objects. In OtherSystem use ScoreSystem and OtherSystem2, etc. We want create universal protocol for all system.

2 Answers 2

4

You have a circular dependency between your two header files (each imports the other). Do not import ScoreSystem.h in Protocol.h, the @class forward declaration is enough. The same goes for your other two imports.

As a general rule I avoid including class header files in other class header files - I just use @class everywhere and import the headers in the implementation files.

Sign up to request clarification or add additional context in comments.

2 Comments

To be clear, though, you'll probably still want to import the headers in the implementation files.
@Chuck: Good catch. I'm going to amend the answer
0

Mine Problem resolved with simple import statement

#import "ProtocolContainingFile.h"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.