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 trialMrunal Kharod
10,657 PointsPass an Array as a Parameter?
Has anyone tried to build an array and pass it as a parameter for the dalesDiner project? if yes can someone show me how can we do that? Thanks.
2 Answers
Michael Buchanan
Courses Plus Student 14,807 PointsHi Mrunal,
You pass in an array by changing the method in TableCheck.m to:
-(void)addMenuItems:(NSArray*)menuItemsArray{
for (MenuItem *menuItem in menuItemsArray) {
[self.itemsOrdered addObject:menuItem.itemName];
self.subtotal += menuItem.itemPrice;
}
}
//Don't forget to change the method call in TableCheck.h to:
-(void)addMenuItems:(NSArray*)menuItemsArray;
//And create an array in your main.m, something like:
NSArray *menuItemsArray = @[grilledCheese, grilledCheese, grilledCheese, soupDuJour, soupDuJour, soupDuJour];
//Then the method call in main.m should read
[table1 addMenuItems:menuItemsArray];
Martin Smith
Courses Plus Student 467 Pointsyou just pass it in like this -methodName:(NSArray*) nameOfArray