I found an explanation why property synthesis is not allowed in categories, but how you can use class extensions :
The following information comes from http://www.friday.com/bbum/2009/09/11/class-extensions-explained/
"Synthesis of the reason was prohibited in categories because synthesis required storage, and it was not possible to effectively declare storage in a category, and was deemed acceptable to allow categories to synthesize methods that could then directly influence ivars classes. Fragile and ugly.
However, it was also obvious that it would be possible to declare a property that was open for reading only, but whose implementation was read for intra-class or framework purposes.
Another requirement is that the synthesis of such properties should always be able to synthesize both the setter and getter naturally and accurately. In particular, when declaring a property as atomic, the developer cannot correctly manually write only 1/2 pairs of getter installers; the locking infrastructure does not open and, therefore, there is no way to guarantee atomicity in such a situation.
Class extensions fixed this problem elegantly.
In particular, you can declare a property like:
@interface MyClass : NSObject @property(readonly) NSView *targetView; @end
And then in the implementation file:
@interface MyClass() @property(readwrite) NSView *targetView; @end @implementation MyClass @synthesize targetView; @end
Final result? A property that is publicly read only, but privately read without revealing properties, up to the entire fragility of pleasure associated with categories.
Rose Perrone Jul 15 '10 at 0:30 2010-07-15 00:30
source share