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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![ariel lowenstein](https://secure.gravatar.com/avatar/ba6a5daeffde204b32eb6f3dea2d269d?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
ariel lowenstein
280 PointsinitWithObjects problem
I can't complete the task. It requires me to add 'toothpaste' 'bread' and 'eggs' into the array shoppingList. I dont know where the problem is. It looks okay.
Thanks.
#import "UIViewController.h"
@interface ViewController : UIViewController
@property (strong, nonatomic) NSString *shoppingCart;
@property (strong, nonatomic) NSArray *shoppingList;
@end
#import "ViewController.h"
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Add your code below!
[self.shoppingList initWithObjects:@"toothpaste",@"bread",@"eggs",nil];
}
@end
1 Answer
![Iris Avalon](https://uploads.teamtreehouse.com/production/profile-photos/278422/micro_gengar.jpg)
Iris Avalon
14,477 PointsLooks like there is a bit of an error over in your ViewController.m file. Down where you have
[self.shoppingList initWithObjects:@"toothpaste",@"bread",@"eggs",nil];
In order to init your shopping list, you need to specifically init it to a NSArray object. Like this!
self.shoppingList = [[NSArray alloc] initWithObjects:@"toothpaste", @"bread", @"eggs", nil];
Your header file knows the shopping list is going to eventually have an NSArray object in it, but in your implementation you'll need instantiate a new array to that object. I hope that doesn't sound too confusing! The header file creates the shoppingList variable, and in your implementation you need to assign an NSArray to it :)
ariel lowenstein
280 Pointsariel lowenstein
280 PointsGreat explanation man!