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

J T
J T
19,878 Points

Self Keyword

I still don't completely understand the self keyword. I've re-listened to the videos explaining it a couple times, and I've looked it up on StackOverflow, but I can't find anywhere that explains it very well. Can someone explain it to me?

3 Answers

Holger Liesegang
Holger Liesegang
50,595 Points

Hi Josh,

let's make this really simple. You've got 3 people (instances/objects) - for example: Britney, Herbert and yourself. Now you might want to refer to Britney's arm, Herber's leg and your head from your point (the actual instance/object) of view/perspective: that would be something like britney.arm, herbert.leg and (your)SELF.head. That's of course not the complete truth of this matter but you might want to think of this like that when starting with object oriented programming :-)

Kind Regards Holger

J T
J T
19,878 Points

Thanks Holger, that makes a little more sense. So it refers to the instance variable you’re using?

Holger Liesegang
Holger Liesegang
50,595 Points

Yeah, simple put It kinda refers to the properties/methods of the class (self/this) which is trying to use their own properties/methods.

Patrick Cooney
Patrick Cooney
12,216 Points

See if this thread from the TTH forums helps.