What do the plus and minus signs mean in Objective-C next to a method?

gyurisc picture gyurisc · Jan 19, 2010 · Viewed 64.3k times · Source

In Objective-C, I would like to know what the + and - signs next to a method definition mean.

- (void)loadPluginsAtPath:(NSString*)pluginPath errors:(NSArray **)errors;

Answer

Georg Schölly picture Georg Schölly · Jan 19, 2010

+ is for a class method and - is for an instance method.

E.g.

// Not actually Apple's code.
@interface NSArray : NSObject {
}
+ (NSArray *)array;
- (id)objectAtIndex:(NSUInteger)index;
@end

// somewhere else:

id myArray = [NSArray array];         // see how the message is sent to NSArray?
id obj = [myArray objectAtIndex:4];   // here the message is sent to myArray

// Btw, in production code one uses "NSArray *myArray" instead of only "id".

There's another question dealing with the difference between class and instance methods.