Initializing Objective C property in child class
Apple recommends that you access the instance variables that back your
properties directly, rather than using a getter/setter, when initializing
a class:
https://developer.apple.com/library/ios/documentation/cocoa/conceptual/ProgrammingWithObjectiveC/EncapsulatingData/EncapsulatingData.html
However, it seems that instance variables backing a property in a parent
class are not accessible in the child class; why is this the case? I'm
extending a class in a library (Cocos2d) where not all the instance
variables are initialized in the parent class init function. For example:
---
@interface parentClass
@property (assign) int myProperty;
----
@interface childClass : parentClass
----
@implementation childClass
- (id) init {
// this doesn't work.
myProperty = 0;
}
No comments:
Post a Comment