0

Possible Duplicate:
Objective-C: Class vs Instance Methods?

Why we put '+' or '-' sign in front of method name in iOS. Please help me on sign logic and what's the difference in that ?

Community
  • 1
  • 1
  • yes, but for confirmation and more explanation, i thought to ask. – Pradeep Singhvi Oct 05 '12 at 10:11
  • No problem, its good to ask for more specification. –  Oct 05 '12 at 10:12
  • "+" Indicates that it is a class method and it will be directly accessible via class name. "-" Indicates, it is a instance method and can be accessible by class instance. – RJ168 Dec 12 '17 at 17:35

5 Answers5

7

It has nothing to do with signs;

+ means the method is a class method, that is, it operates on (or, rather, its scope is) the class itself, not instances. The corresponding thing in many other languages is static.

- means the method is an instance method, that is, it operates on instances of the class.

Joachim Isaksson
  • 176,943
  • 25
  • 281
  • 294
3
`@interface MyClass : NSObject
{
}

+(id) someMethod;  // declaration of class method

-(id) someMethod;  // declaration of instance method

@end` 

Instance methods apply on instances of classes, so they need an object to be applied on and can access their caller's members.

On the other hand class methods apply on the whole class, they don't rely on any object.

check this link for proper knowledge link

Prasad G
  • 6,702
  • 7
  • 42
  • 65
2

A minus - sign denotes an instance method. A plus + sign is a class method.

DrummerB
  • 39,814
  • 12
  • 105
  • 142
2

The leading + sign denotes a class method, the - sign means an instance method.

Side note: this should not be asked here - read that tutorial more carefully.

1

The - prefix denotes an instance method, and the + prefix denotes a class (or static) method.

See this (and many other) SO posts for more information.

Ted
  • 2,525
  • 2
  • 37
  • 54