开发者

What's going on with "expected specifier-qualifier-list" error

开发者 https://www.devze.com 2022-12-26 04:02 出处:网络
It is my GameEngine.h: #import <Foundation/Foundation.h> #import \"Game开发者_开发技巧Array.h\";

It is my GameEngine.h:

#import <Foundation/Foundation.h>
#import "Game开发者_开发技巧Array.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?


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.


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号