开发者

Declaring an objective-c inteface in two separate places

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 *popoverControll开发者_开发百科er;
- (void)configureView;
@end

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


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)


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜