Reputation: 53
I have the following code:
@implementation GameScene {
-(id)init {
self = [super init]
if (self != nil) {
BackgroundLayer *backgroundLayer = [BackgroundLayer node];
[self addChild:backgroundLayer z:0];
GameplayLayer *gameplayLayer = [GameplayLayer node];
[self addChild:gameplayLayer z:5];
}
return self;
}
@end
Ive done it like this before, But ever since I updated xCode I have been recieving the following error messaged all pinned to the -(id) line.
Type name requires a specifier or qualifier
Expected member name or ';' after declaration specifiers
and
Expected ';' at end of declaration list
Im not sure what to do from here, cant seem to fix these!
Upvotes: 2
Views: 7320
Reputation: 36447
It's simple enough. I solved this issue by placing appropriate "{" and "}" braces in code. Your code should be as
@implementation GameScene
-(id)init {
self = [super init]
if (self != nil) {
BackgroundLayer *backgroundLayer = [BackgroundLayer node];
[self addChild:backgroundLayer z:0];
GameplayLayer *gameplayLayer = [GameplayLayer node];
[self addChild:gameplayLayer z:5];
}
return self;
}
@end
Upvotes: 0
Reputation: 12233
You have an open { on your GameScene implementation line.
change your code to
@implementation GameScene
-(id)init {
self = [super init];
if (self != nil) {
BackgroundLayer *backgroundLayer = [BackgroundLayer node];
[self addChild:backgroundLayer z:0];
GameplayLayer *gameplayLayer = [GameplayLayer node];
[self addChild:gameplayLayer z:5];
}
return self;
}
@end
Upvotes: 0
Reputation: 2183
You shouldn't have an opening brace after @implementation
unless you define extra variables in a block, like this:
@implementation GameScene {
int _variable;
}
- (id)init {
...
}
...
@end
The class methods (init, etc) should not be enclosed in braces, so the fix to your compiler error is to simply remove the opening brace.
Upvotes: 6