0

I found the following method in iOS SDK sample code:

@interface DITableViewController (private)
- (NSString *)applicationDocumentsDirectory;
@end

What does (private) means? is it the new syntax for Objective-C 2.0 (developed by Apple)?

Thanks in advance :-)

SeanFang
  • 555
  • 1
  • 4
  • 7

2 Answers2

6

It is just a category. The syntax exist in ObjC 1.0 as well. "private" is the name of the category meaning "It is for private use only". This isn't a keyword.

Defining this category means instances of DITableViewController can be sent the message -applicationDocumentsDirectory as well, without modifying the class DITableViewController itself.

In ObjC 2.0, it may be better to use a class extension for category intended for private use.

@interface DITableViewController ()
- (NSString *)applicationDocumentsDirectory;
@end

(The linked answer provides much more detail.)

Community
  • 1
  • 1
kennytm
  • 510,854
  • 105
  • 1,084
  • 1,005
0

The syntax (category) is used as an alternative to subclassing. They provide a means to add methods to a class, even standard classes, like NSString.

http://macdevelopertips.com/objective-c/objective-c-categories.html

http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/ObjectiveC/Articles/ocCategories.html%23//apple_ref/doc/uid/TP30001163-CH20-SW1

Evan Mulawski
  • 54,662
  • 15
  • 117
  • 144
  • You mention extending classes, but you forgot to mention that category methods can *replace* existing methods, whether you intend that to happen or not. – Richard Jan 30 '11 at 17:10