【问题标题】:Apple SeismicXML Example AppApple SeismicXML 示例应用程序
【发布时间】:2010-11-09 15:37:53
【问题描述】:

在这个类的 SeismicXMLAppDelegate 实现文件中有如下代码:

// 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

【问题讨论】:

    标签: iphone objective-c xml


    【解决方案1】:

    这是一个在 Objective-C 中称为扩展(或匿名类别)

    您可以添加属性、更改其属性并声明新方法,就像在该示例中一样。 为什么不在接口文件中做呢? 那么可能有很多原因,出于设计目的,不暴露某些属性等。

    例如,即使您是#import "SeismicXMLAppDelegate.h",您也不能从RootViewController.m 呼叫myAppDelegate.earthquakeData。 您只能从SeismicXMLAppDelegate 类内部访问earthquakeDataproperty。

    您可以在此处阅读有关类别和扩展的更多信息:The Objective-C Programming Language

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-09-28
      • 1970-01-01
      • 2012-10-31
      • 2010-10-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多