The meaning of an Objective-C class definition

I am learning Objective-C through Cocoa (and love it). I follow the tutorial. There's a class called "Menu" and the interface looks something like this.

@interface Menu: MenuObject {}
@end

@interface MenuLayer : LayerObject {}
-(void) someMethod:(id)sender
-(void) someOtherMethod:(id)sender
@end

and implementations follow the same convention

@implementation Menu
    -(id)init{
        // blah blah blah
    }
@end

@implementation MenuLayer
    // init, someMethod and someOtherMethod stuff here
@end

Which for me looks like two separate objects / classes that are defined and implemented in the same files. Is there a reason for this? Will the result be the same if I split the .h and .m files into Menu.h / .m and MenuLayer.h / .m? Or do I not understand something fundamental?

+5
source share
3 answers

, . , , , , 2 , .

, . "" , .

+5

. , #import , . Objective-C , Java, . , , , , .

+3

Your rating is correct. Two separate classes are declared and defined.

The likely reason for this is that both classes are necessary in order to do what he does Menu. Having both classes in the same header and source just makes the interface more compact.

Splitting it into two files will still work.

+1
source

All Articles