Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.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
Ios 类扩展(匿名类别)中变量的声明与实现_Ios_Objective C_Objective C Category - Fatal编程技术网

Ios 类扩展(匿名类别)中变量的声明与实现

Ios 类扩展(匿名类别)中变量的声明与实现,ios,objective-c,objective-c-category,Ios,Objective C,Objective C Category,我见过很多人在他们的实现文件中使用这样的声明: @interface ViewController ()<UIPickerViewDataSource,UIPickerViewDelegate> @implementation ViewController { UIPopoverController *popoverController; NSString *currentPick; …. } 在这种情况下我有点困惑 提前谢谢。 最好的方法是在类扩展中声明

我见过很多人在他们的实现文件中使用这样的声明:

@interface ViewController ()<UIPickerViewDataSource,UIPickerViewDelegate>

@implementation ViewController
{
  UIPopoverController *popoverController;
      NSString *currentPick;
    ….
}
在这种情况下我有点困惑

提前谢谢。


最好的方法是在类扩展中声明属性。

是的,很抱歉,来自Java的instace变量让我感到困惑,因为将属性转换为objective-c的术语,属性将是实例变量,而在objective-c中,它们显然不是。优点是,在类扩展中定义属性可以自动设置getter和/或setter方法。相关:
@interface ViewController ()
{
  @property (nonatomic, strong) UIPopoverController *popoverController;
  @property (nonatomic, strong) NSString *currentPick;
    ….
}
@implementation ViewController
@synthesize popoverController;
@synthesize currentPick;
...