Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Build a Self-Destructing Message iPhone App Capturing Photo and Video Using UIImagePickerController Resizing an Image and Getting Ready to Send

Jacob McLaws
Jacob McLaws
1,497 Points

Instance vs class method for dummies?

I've taken a look at the stack overflow topic on this and it is a bit over my head. Can anyone help me understand the difference between instance methods and class methods? I know that instance methods are prefaced with - and class with +, but that's all I've clearly understood so far.

1 Answer

Tyler Simko
Tyler Simko
5,610 Points

From 10,000 feet up, classes are types of things and instances are things. For example:

-classes: cars, birds, restaurants -instances: Honda Accord, Robin, Taco Bell

Class methods and instance methods both operate similarly, they're just functions - blocks of code that do something. The only difference is what they operate on, class methods operate on the class as a whole, while instance methods operate on individual instances of the class.

So, for example, a class method for your class Sheep could be something like "herd," which counts all of your sheep. An instance method would be something like "bah," an event that a single sheep could perform.