Take the 2-minute tour ×

My .h file:

#import <Foundation/Foundation.h>
#import "cocos2d.h"
#import "GameData.h"
#import "PROBattleScene.h"

@interface PROBattleAI : NSObject {
    BattleType type;
    PROBattleScene *scene;

-(id)initWithType:(BattleType)_type andBattleInformation:(NSMutableDictionary*)_information andScene:(PROBattleScene*)_scene;

But on the line PROBattleScene *scene; I get the unknown type name error from Xcode.

I tried the answer here: xcode unknown type name but I am already doing that (and doesn't work).

Why is that happening? I am already importing my PROBattleScene.h file, why isn't it being recognized?

EDIT: And the contents of PROBattleScene.h as requested:

#import <Foundation/Foundation.h>
#import "cocos2d.h"
#import "GameData.h"
#import "SimpleAudioEngine.h"

#import "PROBattleBackground.h"
#import "PROBattleAI.h"

@interface PROBattleScene : CCLayer {
    NSMutableDictionary *battleInformation;
    NSMutableArray *localPlayerPartyData;

    PROBattleBackground *background;

    CCNode *base;

    PROBattleAI *enemyAI;

share|improve this question
Show us the contents of PROBattleScene.h as well please. –  mattjgalloway Jul 21 '12 at 17:27
What's in your PROBattleScene.h file? –  Carl Norum Jul 21 '12 at 17:28
And you are defining a type named PROBattleScene (with exactly this spelling/uppercase/lowercase) in your file "PROBattleScene.h"? –  Sven Jul 21 '12 at 17:28
Okay, there is PROBattleScene.h now. –  Just Kidding Jul 21 '12 at 17:35
Declare @class PROBattleScene and remove its header from .h file and import it in .m file. –  Guru Jul 21 '12 at 17:37
add comment

1 Answer

up vote 3 down vote accepted

You have a circular dependency. PROBattleAI imports PROBattleScene which imports PROBattleAI which imports PROBattleScene < zomg infinite loop >

Use @class PROBattleWhatever in your headers as much as possible. Only import headers for protocol definitions or superclasses.

EDIT Ok, the above wording was totally bad...and misleading. Here is what (I believe) happens in detail. Your PROBattleAI imports PROBattleScene, which then imports PROBattleAI, which then imports PROBattleScene for a second time (all before it gets to any of the code in either file). The import will ignore PROBattleScene this time because it has already been imported and you will get the undefined type error since the file was skipped.

share|improve this answer
#import prevents this loop, it is #include which creates this infinite inclusion loop. check this out : stackoverflow.com/questions/439662/… –  samfisher Jul 21 '12 at 17:49
@samfisher #import prevents it from being imported more than once (like C++ #ifndef logic) but it doesn't work well against files the #import each other. –  borrrden Jul 21 '12 at 17:51
Ah, I see. Didn't see that coming. –  Just Kidding Jul 21 '12 at 17:52
@samfisher I will admit my poor wording though, see my updated answer :). –  borrrden Jul 21 '12 at 18:00
add comment

Your Answer


