【发布时间】:2012-03-09 02:06:11
【问题描述】:
使用 ARC,默认情况下每个指针分配都会保留。鉴于此,在非原子情况下,为什么我什至需要声明属性?
这两个有什么不同?
//Property
@interface I1 : NSObject
@property (nonatomic, strong) NSString* str;
@end
I1 *obj1 = ...;
obj1.str = [[NSString alloc] init...];
//Only member variable
@interface I2 : NSObject {
@public
NSString* str;
}
@end
I2 *obj2 = ...;
obj2->str = [[NSString alloc] init...];
【问题讨论】:
-
这个问题听起来很像iOS: must every iVar really be property?。其他相关问题:Why would you use an ivar?
标签: ios automatic-ref-counting