Alex Alex - 3 months ago 9
Objective-C Question

Difference between + and - methods in Objective-c

What is the difference between methods that are declared with - and methods that are declared with +

e.g

- (void)methodname

+ (void)methodname

Answer

Methods prefixed with - are instance methods. This means they can only be invoked on an instance of a class, eg:

[myStringInstance length];

Methods prefixed with + are class methods. This means they can be called on Classes, without needing an instance, eg:

[NSString stringWithString:@"Hello World"];