What is the difference between “+” and “-” before the function name interface declaration in an Objective-C program. Example:
- (void)continueSpeaking;
+ (NSArray *)availableVoices;
What’s the difference?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
+defines a class methodClass methods belong to the class itself, not instances of the class.
Example:
[AppDelegate someMethod]-defines an instance methodExample
[[[UIApplication sharedApplication] delegate] someMethod]One way to describe the difference is that
-methods operate on objects, while+methods operate on the class itself.Say your class was named
MyClass, and you created an instance of it and stored it into a variable calledmyInstance:- (void)continueSpeakingcan be called like so:[myInstance continueSpeaking].However, the method
+ (NSArray *)availableVoicescan only be called like so:[MyClass availableVoices]