Objective-C 属性实际上需要声明 strong 吗?
Is declaring strong actually needed for Objective-C properties?
目前我的理解是(retain)增加了属性的引用计数,本质上和(strong)完全一样。由于默认情况下所有属性都设置为保留(除非另有说明),因此根本不需要添加(强):
@property(nonatomic, strong) NSString *name;
等同于:
@property(nonatomic) NSString *name;
上面两个是一样的吧?
自从引入 ARC 以来,默认设置 "strong"、"atomic" 和 "readwrite"。
这些属性是等价的:
@property NSArray *name;
@property (strong, atomic, readwrite) NSArray *name;
来源:http://useyourloaf.com/blog/default-property-attributes-with-arc.html
来自文档:
By default, both Objective-C properties and variables maintain strong
references to their objects.
所以两种形式是一样的。
目前我的理解是(retain)增加了属性的引用计数,本质上和(strong)完全一样。由于默认情况下所有属性都设置为保留(除非另有说明),因此根本不需要添加(强):
@property(nonatomic, strong) NSString *name;
等同于:
@property(nonatomic) NSString *name;
上面两个是一样的吧?
自从引入 ARC 以来,默认设置 "strong"、"atomic" 和 "readwrite"。
这些属性是等价的:
@property NSArray *name;
@property (strong, atomic, readwrite) NSArray *name;
来源:http://useyourloaf.com/blog/default-property-attributes-with-arc.html
来自文档:
By default, both Objective-C properties and variables maintain strong references to their objects.
所以两种形式是一样的。