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 trialGeoffrey Currie
318 PointsCan you explain self?
Where is THViewController represented by 'self'?
I can see the code in .m starts with 'self' but I'm not sure why.
2 Answers
Stone Preston
42,016 Pointsthe self
keyword refers to the object thats calling the method. so if I have a property of my view controller called numbers and I want to change the value of that property I would use
[self setNumbers:3];
or
self.numbers = 3;
(which calls the setNumbers method behind the scenes)
self in this case refers to the view controller since its the one calling the method
Geoffrey Currie
318 PointsSelf refers to the scope not the class. (having a hard time with all the terminology and what it refers to)
Stone Preston
42,016 Pointsyes, the instance of the class, not the class itself.