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 Methods in Practice

Mrunal Kharod
Mrunal Kharod
10,657 Points

Pass 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

Hi 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];

you just pass it in like this -methodName:(NSArray*) nameOfArray