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

Asked

Viewed 235 times

5

I wanted to know the difference in the time of creating a method using the "+" and "-"?

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

Thank you.

1 answer

9


So, the methods with prefix - are instance methods, i.e., you can only call these methods through an instance of the class:

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

And the 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"];

Browser other questions tagged

You are not signed in. Login or sign up in order to post.