Objective-C accessor declarations (readonly, readwrite, etc)

六月ゝ 毕业季﹏ 提交于 2019-12-03 05:53:13

问题


In the book, "Cocoa Design Patterns," the author sometimes declares a property in the @interface as readonly:

// .h
@property (readonly, copy) NSArray *shapesInOrderBackToFront;

and then later adds an unnamed category to the implementation (.m) file like this:

// .m
@interface MYShapeEditorDocument ()
@property (readwrite, copy) NSArray *shapesInOrderBackToFront;
@end

Any idea as to why? It's unclear to me how this approach is better than, or more necessary than, initially declaring the property as "readwrite".


回答1:


Externally the property will be readonly. While inside the class it will have both the accessor, and the setter.

The setter will not be visible by the compiler outside of the implementation(.m) file.



来源:https://stackoverflow.com/questions/1876495/objective-c-accessor-declarations-readonly-readwrite-etc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!