One strong advantage of class extension is that with class extension you can declare a readonly property in the header file and override this property in class extension as readwrite property. Like below :
//SomeClass.h
@interface SomeClass : NSObject
{
NSInteger someInt; //with modern runtime you can omit this line
}
@property (readonly) NSInteger someInt;
@end
//SomeClass.m
@interface SomeClass ()
@property (readwrite) NSInteger someInt;
@end
@implementation SomeClass
@synthesize someInt;
@end
But if you use a modern runtime ,you can also declare a totally new property in the class extension (which also generate an iVar for that property if there isn't).
//SomeClass.h
@interface SomeClass : NSObject
{
}
@end
//SomeClass.m
@interface SomeClass ()
@property (readwrite) NSInteger someInt;
@end
@implementation SomeClass
@synthesize someInt;
@end
Here's my question : I think declare a totally new property in class extention is somehow has some side effects. Because class extension my not be in the header file and someone else who subclass the class may not know about that "secret property". And if he declare a property with the same name of that "secret property". And this new property's getter and setter method will override the super class's. Isn't this a problem?And why would modern runtime allow such thing happen?
EDIT I posted another question about this topic , please check it out: The risk of declare new propery in class extension (Ojbective-C) , how to solve it?