I have the following class and subclass:
@interface NSHigh : NSObject
@property (nonatomic, strong) NSArray *array;
@end
@implementation NSHigh
-(NSArray*)array
{
_array = [[NSArray alloc] init];
return _array;
}
@end
@interface NSLow : NSHigh
@end
@implementation NSLow
/* synthesizing makes the assertion FAIL. NO synthesizing makes the assertion PASS */
@synthesize array;
@end
Then I run this code somewhere:
NSLow *low = [[NSLow alloc] init];
assert(low.array);
So, apparently, if in the subclass NSLow
I synthesize the array property, then the getter from the super class does not get called, and the assertion fails.
If I do not synthesize, then the superclass getter is called, and the assertion passes.
- Why does this happen?
- How would I access the array instance variable in the
NSLow
subclass without callingself.array
every time?