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;
...