In the context of a class definition, +/-
determine whether the methods are instance or class level methods.
+
indicates the method is class level, and you don't need an instance to call it.
-
indicates the method is an instance method, and must be called through an instance of an object.
A common example of a static (+) method is NSString::stringWithFormat
, when you call it, you do so without an instance, but rather using the class name:
[NSString stringWithFormat: @"Your age is %d", age];
An instance method must be called on an instance of an appropriate object, an example of one would be:
NSString *s = @"oop:ack:zonks::ponies";
int len = [s length]; // instance method called
These symbols should not be confused with the mathematical operators +
and -
, which can only be applied as part of binary or unary arithmetic expressions.