Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

+(void) or -(void) difference? [duplicate]

Possible Duplicates:
Objective-C: Class vs Instance Methods?
What do the plus and minus signs mean in Objective C next to a method?

I've tried to look around and couldn't come up with a solid answer that really explained my confusion. I've seen a few times and that is a class having a method that has it's "method type" set to "+" ie:

-(Fraction*) fractionWithNumerator: (int) n denominator: (int) d;
now how is that different to
+(Fraction*) fractionWithNumerator: (int) n denominator: (int) d;

like image 453
cdnicoll Avatar asked Jul 09 '10 19:07

cdnicoll


2 Answers

"+" is a method called on the class. "-" is a method called on an instance.

  • +alloc: because you would say [NSString alloc]

  • -init: because you would call init on an instance rather than saying [NSString init]

like image 146
Rebecca Chernoff Avatar answered Nov 11 '22 12:11

Rebecca Chernoff


The difference is one is a class method(+) and the other is an instance method(-). Details

like image 43
unholysampler Avatar answered Nov 11 '22 12:11

unholysampler