xcode 未知类型名称

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11594336/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 00:57:51  来源:igfitidea点击:

Unknown type name

objective-ciosxcodecocos2d-iphone

提问by Voldemort

My .h file:

我的 .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

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

但是在线上PROBattleScene *scene;我从 Xcode 得到了未知的类型名称错误。

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

我在这里尝试了答案:xcode unknown type name但我已经这样做了(并且不起作用)。

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

为什么会这样?我已经在导入我的PROBattleScene.h文件,为什么没有被识别?

EDIT: And the contents of PROBattleScene.has requested:

编辑:和PROBattleScene.h要求的内容:

#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

回答by borrrden

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

你有一个循环依赖。PROBattleAI 导入 PROBattleScene 导入 PROBattleAI 导入 PROBattleScene< zomg无限循环>

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

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

EDITOk, 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.

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