What is the difference between class and instance methods in Objective-C and when should I use each of them?
What is the difference between class and instance methods in Objective-C and when should
Share
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.
Using the tired old Car analogy…
Think of a Class like it is a factory that makes Instances of the class. For example, you might have a Car class and you might declare a method like:
And that method would then create a new Car instance, set the color, and return it:
Now, that Car class would then declare an instance method that allows the car to be painted. Why an instance method? Because every car can have a different color (and the color of the car would likely be stored in an instance variable).
This is explained in the Objects, Classes, and Messaging section of the Objective-C documentation.