7

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;

Community
  • 1
  • 1
cdnicoll
  • 574
  • 1
  • 6
  • 17
  • See [What do the plus and minus signs mean in Objective C next to a method? ](http://stackoverflow.com/questions/2097294/what-do-the-plus-and-minus-signs-mean-in-objective-c-next-to-a-method) – Matthew Flaschen Jul 09 '10 at 19:42
  • This one answered it for me: http://stackoverflow.com/questions/1053592/objective-c-class-vs-instance-methods – jsherk Jul 15 '12 at 17:40

2 Answers2

10

"+" 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]

Rebecca Chernoff
  • 22,065
  • 5
  • 42
  • 46
  • All covered in the wonderful Objective-C documentation: http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/ObjectiveC/Introduction/introObjectiveC.html – bbum Jul 09 '10 at 19:42
4

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

Community
  • 1
  • 1
unholysampler
  • 17,141
  • 7
  • 47
  • 64