I do not have anything in particular to achieve, but rather I am trying to learn more about class extension.
This is the explanation of class extension directly from apple Categories and extensions:
@interface MyClass : NSObject
@property (retain, readonly) float value;
@end
// Private extension, typically hidden in the main implementation file.
@interface MyClass ()
@property (retain, readwrite) float value;
@end
it does make perfect sense to me, however, supposing I have a MyClass2 extending MyClass:
@interface MyClass2 : MyClass
@property (retain, readwrite) float value;
@end
so I have few questions, which I could easily answer if class extensions weren't involved:
First off, the properties should be 'assign' not 'retain' since they are scalar types.
Changing the writability in class extensions or subclasses are common patterns to implement publicly read-only but privately writable properties and mutable subclasses of immutable classes, respectively. The Apple Objective-C Programming Guide has a good discussion.
To answer your first question, only methods declared in MyClass, or any of its super-classes, are visible from within MyClass. Your private class extension declares the setter in scope to the implementation, so that will get called. The readwrite declaration in the interface for MyClass2 merely brings the setter in to the public scope. The implementation is still in MyClass.
The answer to your second question is no, a warning is not issued. Changing writability from read-only to read-write is valid.
Finally, there is only one ivar. Accessing it from MyClass2 affects the same ivar visible in MyClass.