17

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".

RyJ
  • 3,995
  • 6
  • 34
  • 54

1 Answers1

40

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.

Bryan McLemore
  • 6,438
  • 1
  • 26
  • 30
  • 1
    What if everything above is the same, but MYShapeEditorDocument is extended to MYShapeEditorDocumentExtended. Does MYShapeEditorDocumentExtended still have the same read access externally and readwrite internally for the MYShapeEditorDocumentExtended class? – jdog Oct 30 '12 at 18:33