Briefly, I have a class implementation:
@implementation ClassB: ClassA
-(id) init {
if (self = [super init]) {
...
}
return self;
}
@end
And a category, in two variants:
1:
@implementation ClassA (ClassA_Category)
+(id) alloc {
if ([self isEqual: [ClassA class]]) {
return [ClassB alloc];
} else {
return [super alloc];
}
}
@end
2:
@implementation ClassA (ClassA_Category)
+(id) alloc {
return [[ClassB superclass] superclass] alloc];
}
@end
The question is about this simple initialization:
ClassA *aObj = [[ClassA alloc] init];
For the first category variant, init
of ClassB
is called, but for the second case - doesn't.
Why ? Does these two alloc
constructions have the same meaning ?