<分区>
Possible Duplicate:
With ARC why use @properties anymore?
注意:我实际上不认为我们可以取消属性,但我试图理解为什么不这样做的原因。 :)
回到 this question ,似乎我们使用属性的主要原因是为了避免内存管理问题。换句话说,通过创建属性,我们摆脱了编写所有这些保留和释放方法的需要:
- (void) setOtherObj:(MyOtherObject *)anOtherObject {
if (otherObject == anOtherObject) {
return;
}
MyOtherObject *oldOtherObject = otherObject; // keep a reference to the old value for a second
otherObject = [anOtherObject retain]; // put the new value in
[oldOtherObject release]; // let go of the old object
}
既然 ARC 现在处理这个问题,我们是否可以不一起取消属性并通过像 otherObject = anotherObject
这样的方式设置 ivars?