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

kirkbyo
kirkbyo
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,

Ozzie

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.