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.

iOS Object-Oriented Objective-C Diving Deeper - Classes, Properties and Methods Custom Classes Continued

Can't understand 2 lines in the code. Details below.

First I paste the code:

-(id) init {

    self = [super init];

if (self) {

    self.itemsOrdered = [[NSMutableArray alloc] init];


return self;


We already assigned the value which is returned by the init method from the super class. If we did this why do we have to check if self is empty or not ? Are there situations where we can get back a "no value" from super?

table1.itemsOrdered = [[NSMutableArray alloc] init];

I need a more detailed explanation especialy on the left side of the = .

This line is confusing to me because until now we declared an NS type array like this: NSMutableArray *nameOfArray = [[NSMutableArray alloc]init];


table1 - is the object from the TableCheck Class

[[NSMutableArray alloc] init] - allocates and initializes a space in the memory


Gabe says that itemsOrdered is the array. Is this a shortened way to declare an array ? In the TableCheck Class subtotal, tip, isTakeOut were declared in the header file at the @property section. It is not mandatory to declare all objects in @property that will be used in the program? Does the . operator in table1.itemsOrdered returns a value ?

If the dot operator can be replaced by brackets, then why brackets aren't working here?

//using the dot syntax
table1.itemsOrdered = [[NSMutableArray alloc] init];

//using brackets
[table1 itemsOrdered] = [[NSMutableArray alloc]init];