我的主题是“使用类扩展来隐藏私人信息”(pdf的第73页)它说:
Class extensions are often used to extend the public interface with additional private methods or properties for use within the implementation of the class itself. It’s common, for example, to define a property as readonly in the interface, but as readwrite in a class extension declared above the implementation, in order that the internal methods of the class can change the property value directly.
我在这个语句中不理解的是,因为我们可以在类扩展中定义的任何私有方法中更改readonly属性,而不在类扩展中将该属性重新声明为readwrite,它通过重新声明实现了什么?该属性为readwrite?
答案 0 :(得分:0)
您始终可以通过其实例变量(_ivar = ...
)更改属性,但除非您将其重新声明为{,否则您将无法使用点属性语法(self.myProp =...
)更改该属性{1}}。在这种情况下,您还需要提供其他信息,例如该属性是readwrite
还是strong
。
答案 1 :(得分:0)
_Make
)。实际上并非如此(至少在Xcode 4.6.3中没有)。它具有相同的名称具有属性本身(除非您自己合成实例变量@synthesize Make = _Make;
如果我错了,请纠正我