I\'m reading through Mark Dalrymple\'s Learn Objective-C on the Mac (only at the chapter on Protocols, so still relatively newbish) and trying to figure something out:<
I found a condition under which [ ClassName alloc ] and [ self alloc ] were not equivalent. I am listing it in case others are faced with a similar situation.
//Option 1
+ (NSInputStream *)streamWBlockWithArray:(NSArray *)dataArray
{ return [[[self alloc] initWithArray:dataArray] autorelease]; }
// Option 2
+ (NSInputStream *)streamBlockWithArray:(NSArray *)dataArray
{ return [[[Block alloc] initWithArray:dataArray] autorelease]; }
If I use option 1, the compiler was giving a compiler error of duplicate definitions the definition of initWithArray was being flagged as conflicting with the definition from + [ NSArray initWithArray ]. The compiler error went away after I replaced [ self alloc ] by [ Block alloc ]. This is probably just a compiler unable to disambiguate even though the context seems clear enough.