What's going on with “expected specifier-quali

2019-02-19 17:22发布

It is my GameEngine.h:

#import <Foundation/Foundation.h>
#import "GameArray.h";


@interface GameEngine : NSObject {
    GameArray *gameButtonsArray;
}

@property (nonatomic, retain) GameArray *gameButtonsArray;

And this is my GameArray.h:

#import <Foundation/Foundation.h>
#import "MyAppDelegate.h";

@interface GameArray : NSObject {
    NSMutableArray *gameButtonsArray;

}
@property (nonatomic, retain) NSMutableArray *gameButtonsArray;

It keep prompt my "expected specifier-qualifier-list" error i my GameEngine.h, and error said that "expected specifier-qualifier-list before 'GameArray'", what's going on?

3条回答
太酷不给撩
2楼-- · 2019-02-19 18:04

Lose the semi-colon on line 2 in your .h file

查看更多
手持菜刀,她持情操
3楼-- · 2019-02-19 18:16

If removing the unnecessary semicolons does not fix your problem, most likely MyAppDelegate.h imports GameEngine.h creating a circular dependency between the GameEngine.h and GameArray.h. Try removing the #import "GameArray.h" from GameEngine.h and replacing it with:

@class GameArray;

Also add

#import "GameArray.h"

to GameEngine.m below the import of GameEngine.h

查看更多
做个烂人
4楼-- · 2019-02-19 18:17

This is the best practice.

GameEngine.h

#import <Foundation/Foundation.h>

@class GameArray;

@interface GameEngine : NSObject {
    GameArray *gameButtonsArray;
}

@property (nonatomic, retain) GameArray *gameButtonsArray;

Then in GameEngine.m

#import "GameEngine.h"
#import "GameArray.h"

@implementation GameEngine    
//...
@end

This prevents circular references wherein one header imports a second header which imports the first which imports the second and so on in an endless cycle.

查看更多
登录 后发表回答