Usually, an additional @interface is placed for placement, which defines a category containing private methods:
Person.h:
@interface Person { NSString *_name; } @property(readwrite, copy) NSString *name; -(NSString*)makeSmallTalkWith:(Person*)person; @end
Person.m:
@interface Person () //Not specifying a name for the category makes compiler checks that these methods are implemented. -(void)startThinkOfWhatToHaveForDinner; @end @implementation Person @synthesize name = _name; -(NSString*)makeSmallTalkWith:(Person*)person { [self startThinkOfWhatToHaveForDinner]; return @"How your day?"; } -(void)startThinkOfWhatToHaveForDinner { } @end
"Personal category" (the proper name for an unnamed category is not a "private category", it is a "class extension") .m prevents the compiler from warning that the methods are defined. However, since the @interface in the .m file is a category, you cannot define ivars in it.
August 6th update '12: Objective-C has evolved since this answer was written:
Benedict Cohen Oct 19 '10 at 10:35 2010-10-19 10:35
source share