I am very new in objective c and in xcode. I would like to know that what are the +
and -
signs next to a method definition mean.
- (void)loadPluginsAtPath:(NSString*)pluginPath errors:(NSArray **)errors;
I am very new in objective c and in xcode. I would like to know that what are the +
and -
signs next to a method definition mean.
- (void)loadPluginsAtPath:(NSString*)pluginPath errors:(NSArray **)errors;
+
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.
+ methods are class methods - that is, methods which do not have access to an instances properties. Used for methods like alloc or helper methods for the class that do not require access to instance variables
- methods are instance methods - relate to a single instance of an object. Usually used for most methods on a class.
See the Language Specification for more detail.
the objective c programming guide is good resource to start with