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 trialjozsefgyongyosi
638 PointsCan'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];
Here:
table1 - is the object from the TableCheck Class
[[NSMutableArray alloc] init] - allocates and initializes a space in the memory
BUT:
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 ?
jozsefgyongyosi
638 Pointsjozsefgyongyosi
638 PointsIf 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];