What's the difference between - and + when declaring with Cocoa/Obj-C.
e.g.
-(void)doSomething{}
or
+(void)doSomething{}
What's the difference between - and + when declaring with Cocoa/Obj-C.
e.g.
-(void)doSomething{}
or
+(void)doSomething{}
"-
" means an instance method (meaning relative to a specific object), while "+
" means a class method (meaning usable by a class in general—it doesn't have to be tied to a specific object).
Example:
For "- (void)doSomething
":
MyClass *obj = [[MyClass alloc] init];
[obj doSomething];
vs
[MyClass doSomething];
for "+ (void)doSomething
".
Just to add a little analogy to htw's answer: