在一个属性中声明多个对象

时间:2016-09-30 06:44:01

标签: objective-c

我注意到很多人在模特中分别声明了多个属性。像这样,例如:

@property ( strong , nonatomic ) NSMutableString *name;
@property ( strong , nonatomic ) NSMutableString *surname;
@property ( strong , nonatomic ) NSMutableString *fatherName;

我理解在ViewControllers的情况下,我们单独定义它们,因为每个插座都连接到它自己的对象。例如:

@property ( weak , nonatomic ) IBOutlet UIView *view;
@property ( weak , nonatomic ) IBOutlet UIImageView *imageView;
@property ( weak , nonatomic ) IBOutlet UITextfield *textfield;

我想知道为什么每个人都单独定义它们。这可能是因为内存管理,您希望将某些属性声明为弱,有些属性为强。尽管如此,即使情况并非如此,我也从未见过一个人宣称这样的属性:

@property ( strong , nonatomic ) NSMutableString *name , *surname , *fatherName ;

这背后的原因是什么?我测试了我给出的两个例子,它们运行良好。我有什么遗漏或不理解的东西吗?

1 个答案:

答案 0 :(得分:2)

在一行中声明相同类型的多个(非出口)属性的语法非常好。该功能与每行声明一个属性的标准方法完全相同。