2010-11-09 48 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