What is the difference between the + and - sign in Objective-C

5

I wanted to know what the difference is when I create a method using the "+" and "-"?

And also when to use and why to use, I usually only use the "-", but I do not know how to use the method with "+".

Thank you.

    
asked by anonymous 21.07.2014 / 04:21

1 answer

9

Thus, methods with - are instantiation methods, that is, you can only call these methods through an instance of the class:

NSString *instanciaString = [[NSString alloc] init];
[instanciaString length];

And methods with the + prefix are class methods. These methods do not need an instance to be called, you can call directly from the class, for example:

[NSString stringWithString:@"Hello World"];
    
21.07.2014 / 12:31