I have two basic classes that inherits each other:
BaseClass:
// .h
@interface BaseClass : NSObject
@property int myProperty;
@end
// .m
@synthesize myProperty = _myProperty;
ChildClass:
// .h
@interface Child : BaseClass
@end
In ChildClass.m, I want to access BaseClass myProperty‘s getter/setter using the _myProperty ivar:
// ChildClass.m
_myProperty = 1;
Of course, the parent’s @synthesize isn’t visible from ChildClass, so I can’t just use _myProperty.
If I put @synthesize myProperty = _myProperty in ChildClass.m, the parent’s getter/setter are overridden, and that’s not what I want.
Is there a way to make an alias without overriding parent’s methods ?
Declare it manually. Then, you can have complete control over the scope access of the iVars.
@protectedgives subclass access, and@packagemakes it visible to everything in the implementation image (not really useful in iOS where you can’t implement your own shared framework images).For more details:
http://developer.apple.com/library/ios/#documentation/cocoa/conceptual/objectivec/Chapters/ocDefiningClasses.html