views:

50

answers:

3

When you start a SplitViewController-based project for the iPad, it creates a DetailViewController. In DetailViewController.h, it declares the interface as normal:

@interface DetailViewController : UIViewController <UIPopoverControllerDelegate, UISplitViewControllerDelegate> {

        UIPopoverController *popoverController;
        UIToolbar *toolbar;

        id detailItem;
        UILabel *detailDescriptionLabel;
}

Then, in the implementation file (DetailViewController.m), it declares some other parts of the interface:

@interface DetailViewController ()
@property (nonatomic, retain) UIPopoverController *popoverController;
- (void)configureView;
@end

Why do they do this? What is the point of declaring the interface in two different places/files?

+4  A: 

They've created a private category. The methods defined in the .m are only supposed to be used within the .m and are not part of the advertised interface into the DetailViewController. External users of the controller are only expected to call those methods defined in the .h, internal users can also use those in the private category. It is common to also see

@interface DetailViewController (Private)
Peter
+1, except it's officially called a "Class extension".
Dave DeLong
A: 

The first is the public interface while the second is a "class continuation" and contains private methods.

Sven
+3  A: 

It's to extend the standard interface with extra methods that you can implement for that specific implementation so that the compiler knows about them.

See Apple's documentation on class extensions for details.

BoltClock
+1 for the doc link
Dave DeLong