Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.


15,791 Points

Having trouble understanding a few concepts

I am having trouble understanding a few things with Objective-C. The first thing is self, I don't understand when to use it and when not too. Another concept that is not very clear to me is when to use square brackets. Ex: [self.tableView indexPathForSelectedRow]

Thank you in advance,


1 Answer

Info on self: Self is really just a way to refer to the object that receiving this message..

Self description on Apple Docs

Here's a little info on brackets and general Obj-C info

Objective-C maintains all the same syntax and features of C. The object-oriented features that were added were done so in the model of Smalltalk, in which we send messages to objects (more on these later) in this manner:

mug makeEmpty (The makeEmpty message is sent to the mug object.) In Objective-C we simply surround such actions with square brackets:

[mug makeEmpty] What may seem like an arbitrary collection of brackets at first will, with time and practice, make sense as a mechanism for organizing code around these object-oriented concepts that were added as a thin layer on top of the world of C code.