2010-11-09 49 views
1

在这个类中,有下列代码的SeismicXMLAppDelegate实现文件:苹果SeismicXML示例应用

 

// forward declarations 

@interface SeismicXMLAppDelegate() 



@property (nonatomic, retain) NSURLConnection *earthquakeFeedConnection; 

@property (nonatomic, retain) NSMutableData *earthquakeData; // the data returned from the NSURLConnection 

@property (nonatomic, retain) NSOperationQueue *parseQueue;  // the queue that manages our NSOperation for parsing earthquake data 



- (void)addEarthquakesToList:(NSArray *)earthquakes; 

- (void)handleError:(NSError *)error; 

@end 
 

为什么他们在实现文件的第二接口?

http://developer.apple.com/library/ios/#samplecode/SeismicXML/Listings/Classes_SeismicXMLAppDelegate_m.html#//apple_ref/doc/uid/DTS40007323-Classes_SeismicXMLAppDelegate_m-DontLinkElementID_10

回答

2

这是一种称为一个扩展(或匿名类)的Objective-C

您可以添加属性,更改其属性,并宣布新的方法,如在这个例子。 为什么不在界面文件中做它? 那么有可能是一个很大的原因,设计目的,不暴露的一些属性。等

例如,你不能从RootViewController.m即使你#import "SeismicXMLAppDelegate.h"调用myAppDelegate.earthquakeData。 您只能从SeismicXMLAppDelegate类的内部访问earthquakeData属性。

您可以在这里阅读更多关于分类和扩展:The Objective-C Programming Language