Objective c 未知类型名

Objective c 未知类型名,objective-c,ios,xcode,cocos2d-iphone,Objective C,Ios,Xcode,Cocos2d Iphone,我的.h文件: #import <Foundation/Foundation.h> #import "cocos2d.h" #import "GameData.h" #import "PROBattleScene.h" @interface PROBattleAI : NSObject { BattleType type; PROBattleScene *scene; } -(id)initWithType:(BattleType)_type andBattleI

我的.h文件:

#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;
-(void)dealloc;
@end

你有一个循环依赖。PROBattleAI导入PROBattleScene,后者导入PROBattleAI,后者导入PROBattleScene

尽可能在标题中使用
@class-probattlewhich
。仅导入协议定义或超类的标题


编辑好的,上面的措词完全不好……而且具有误导性。下面是(我相信)发生的细节。您的PROBattleAI导入PROBattleScene,然后PROBattleAI导入PROBattleScene,然后第二次导入PROBattleScene(都是在它到达任一文件中的任何代码之前)。这次导入将忽略PROBattleScene,因为它已经被导入,并且由于跳过了该文件,您将得到未定义的类型错误。

请同时向我们显示
PROBattleScene.h
的内容。您的
PROBattleScene.h
文件中有什么?您正在定义一个名为
PROBattleScene
(正是这个拼写/大写/小写)在您的文件“PROBattleScene.h”中好的,现在有了
PROBattleScene.h
。声明@class PROBattleScene并从.h文件中删除其头并将其导入到.m文件中。
#import
阻止了这个循环,是
#include
创建了这个无限包含循环。请检查:@samfisher#import阻止它被多次导入(像C++ + IFNDEF逻辑),但是它对文件的作用不太好。
#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;
}
+(CCScene*)scene;
-(id)init;
-(void)loadBattleInformation;
-(void)loadBGM;
-(void)loadBackground;
-(void)loadBase;
-(void)loadEnemyAI;
-(void)beginBattle;

@end