views:

532

answers:

4

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;
+16  A: 

+ 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.

Georg
It's almost as if the extra five characters of "static" are somehow too much for them.
Anon.
Link to docs: http://developer.apple.com/mac/library/DOCUMENTATION/Cocoa/Conceptual/ObjectiveC/Articles/ocDefiningClasses.html#//apple_ref/doc/uid/TP30001163-CH12-TPXREF122
Seth
@Seth: Thanks, I was looking for that link but didn't find it.
Georg
@Anon: The methods aren't static. They are class methods. They can be overridden and are very much a part of the class hierarchy. static implies something very different in C.
bbum
@Avon, that's apple for you, they'll leave out a flash on their camera too, and a right button on their mice. =)
pokstad
@bbum is on the money. The fact that Java re-appropriated the "static" keyword to mean something different is not the fault of the much-older C. While its usage may not be entirely intuitive in C, it seems even less so in Java. I would expect static to be the opposite of dynamic — something which doesn't change. And of course, the Objective-C language was around for nearly 15 years before Apple adopted it in OS X.
Quinn Taylor
+4  A: 

+ 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.

Robert Christie
+2  A: 

the objective c programming guide is good resource to start with

Ahmed Kotb
+1  A: 

http://www.otierney.net/objective-c.html

aaa