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