self class

Discussion in 'Mac Programming' started by teguh123, Apr 14, 2011.

  1. macrumors member

    Mar 22, 2011
    Is this code correct

    @implementation Vehicle +(id) vehicleWithColor:(NSColor*)color {
    id newInstance = [[[self class] alloc] init]; // PERFECT, the class is // dynamically identified
    [newInstance setColor:color]; return [newInstance autorelease];
    } @end
    Why use [self class]

    I thought self already points to the class on static methods (the ones with +)
  2. macrumors member

    Jun 12, 2008

Share This Page