Objective-C access announcements (read-only, readwrite, etc.)

In Cocoa Design Patterns, the author sometimes declares a property in @interface as read-only:

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

and then adds an unnamed category to the implementation file (.m) as follows:

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

Any idea on why? I don’t understand how this approach is better or more necessary than initially declaring the readwrite property.

+16
properties objective-c category
Dec 09 '09 at 20:07
source share
1 answer

Externally, the property will be read-only. Inside the class, it will have both an accessor and a setter.

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

+39
Dec 09 '09 at 20:13
source share



All Articles