Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 地产及;私营及私营机构;接口的扩展类组合_Objective C_Cocoa_Interface_Properties_Categories - Fatal编程技术网

Objective c 地产及;私营及私营机构;接口的扩展类组合

Objective c 地产及;私营及私营机构;接口的扩展类组合,objective-c,cocoa,interface,properties,categories,Objective C,Cocoa,Interface,Properties,Categories,我下载了AA绘图图的示例代码 其中一个.h文件: @interface MainViewController : UIViewController <APYahooDataPullerDelegate, CPPlotDataSource> { CPLayerHostingView *layerHost; @private APYahooDataPuller *datapuller; CPXYGraph *graph; } @property (nona

我下载了AA绘图图的示例代码

其中一个.h文件:

@interface MainViewController : UIViewController <APYahooDataPullerDelegate, CPPlotDataSource> {
    CPLayerHostingView *layerHost;
@private
    APYahooDataPuller *datapuller;
    CPXYGraph *graph;
}    
@property (nonatomic, retain) IBOutlet CPLayerHostingView *layerHost;
@end
我在示例项目的主视图控制器代码中找到了上述代码

如果我执行以下操作,上面的代码和下面的代码有什么区别

@interface MainViewController : UIViewController <APYahooDataPullerDelegate, CPPlotDataSource> {
    CPLayerHostingView *layerHost;
    APYahooDataPuller *datapuller;
    CPXYGraph *graph;
}    
@property (nonatomic, retain) IBOutlet CPLayerHostingView *layerHost;
@property(nonatomic, retain) CPXYGraph *graph;
@property(nonatomic, retain) APYahooDataPuller *datapuller;
@end
@interface MainViewController:UIViewController{
CPLayerHostView*layerHost;
APYahooDataPuller*数据提取器;
CPXYGraph*图;
}    
@属性(非原子,保留)IBOutlet CPLayerHostView*layerHost;
@属性(非原子,保留)CPXYGraph*graph;
@属性(非原子,保留)APYahooDataPuller*datapuller;
@结束
您在.m文件中看到的“额外”内容是一个。最初的程序员可能只是想在类的公共接口(在.h文件中)中隐藏一些实现细节,所以他创建了一个类别(在本例中没有名字,这就是为什么
()
中没有任何内容)来将其添加到实现文件中。在这个特定的例子中,他隐藏了私有变量的访问器,这样外部代码就无法访问它们

在第二个代码段中显示的更改将所有内容都放在一个类接口中。这些更改不应该影响运行时操作。(除了您取出了
@private
,这是故意的吗?)语义上的区别在于,category方法是在运行时添加到类中的


类别只能添加方法,而不能添加实例变量,这就是为什么原始代码在原始
@interface
块中有所有实例变量声明(甚至那些带有“secret”访问器的声明)。

我喜欢你的想法,通过类别“secret”访问。+1这是Cocoa编程中非常常见的模式。正如您所说的,内部类别用于向类的用户隐藏访问器。该语法与category语法类似,但它产生不同的输出。
@interface MainViewController : UIViewController <APYahooDataPullerDelegate, CPPlotDataSource> {
    CPLayerHostingView *layerHost;
    APYahooDataPuller *datapuller;
    CPXYGraph *graph;
}    
@property (nonatomic, retain) IBOutlet CPLayerHostingView *layerHost;
@property(nonatomic, retain) CPXYGraph *graph;
@property(nonatomic, retain) APYahooDataPuller *datapuller;
@end