Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I am doing tutorials to learn Cocos2d and have a question. here is the .m code:

#import "SceneManager.h"

@interface SceneManager ()
   +(void) go: (CCLayer *) layer;
   +(CCScene *) wrap: (CCLayer *) layer;
@end


@implementation SceneManager

    +(void) goPlay {
        CCLayer *layer = [PlayLayer node];
        [SceneManager go: layer];
}

+(void) go: (CCLayer *) layer {
    CCDirector *director = [CCDirector sharedDirector];
    CCScene *newScene = [SceneManager wrap:layer];

//    Class transition = nextTransition();

    if ([director runningScene]) {
         [director replaceScene:newScene];
}else {
    [director runWithScene:newScene];
}
}

+(CCScene *)wrap: (CCLayer *) layer {
    CCScene *newScene = [CCScene node];
    [newScene addChild: layer];
    return newScene;
}

@end

My question is why is there an @interface placed in the .m file and not included in the .h file?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

That @interface Class () placed in the implementation file is a class extension to the SceneManager class which defines its private interface.

It's being used because go and wrap are only used by the implementation of this class and nowhere else (i.e. it's a private interface).

The @private modifier only works on variables, not on methods, so this is the way to hide them.

(Source: stackoverflow)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.