Just for add some tests:
I have created 2 MyClass classes: NSObject -> Myclass -> My2ndClass
So:
@implementation Myclass +(id) sharedClass { static Myclass *miclase = nil; miclase = [[self alloc] init]; NSLog(@"%@", [super description]); return miclase; } -(id)init { self = [super init]; NSLog(@"init de Myclass"); return self; } -(NSString *)description { return @"i am Myclass"; } @end
AND:
@implementation My2ndClass +(id) sharedClass { static My2ndClass *miclase = nil; miclase = [[super alloc] init]; //miclase = [super init]; CRASH NSLog(@"%@", [super description]); return miclase; } -(id)init { self = [super init]; NSLog(@"init de My2ndClass"); NSLog(@"%@", [super description]); return self; } -(NSString *)description { return @"i am My2ndClass"; } @end
Then in AppDelegate:
Myclass *miclase = [Myclass sharedClass]; My2ndClass *mi2ndclase = [My2ndClass sharedClass];
This is the console output:
2012-09-03 17:18:55.742 Dynamic Typing[2891:207] init de Myclass 2012-09-03 17:18:55.744 Dynamic Typing[2891:207] Myclass 2012-09-03 17:18:55.746 Dynamic Typing[2891:207] init de Myclass 2012-09-03 17:18:55.747 Dynamic Typing[2891:207] init de My2ndClass 2012-09-03 17:18:55.748 Dynamic Typing[2891:207] i am Myclass 2012-09-03 17:18:55.751 Dynamic Typing[2891:207] My2ndClass
Like xlc0212 told, the correct messages when they are nested are:
miclase = [super alloc]; miclase = [miclase init];
Besides, if i do
miclase = [super alloc]
and then
miclase = [super init]
it CRASHES.
When is sent a class method (+) [super description], it logs class name (Myclass and My2ndClass). They are de class itself and don't have super object, do they?
allocmethod?allocmethod? otherwise I cannot see any reason of usingsuper