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 trialStefan Mach
3,691 PointsI think this code challenge is broken.
The code challenge says I am not adding all three items but they are all there, no typos.
Can someone please correct the challenge so it recognizes what is the case. I tested by creating a syntax error and checking preview. It would say I had only one error, so I fixed it, and all it says is I don't have three items listed.
#import "UIViewController.h"
@interface ViewController : UIViewController
@property (strong, nonatomic) NSString *shoppingCart;
@property (nonatomic, strong) NSArray *shoppingList;
@end
#import "ViewController.h"
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Add your code below!
NSArray *shoppingList = [[NSArray alloc] initWithObjects: @"toothpaste", @"bread", @"eggs", nil];
}
@end
1 Answer
Martin Wildfeuer
Courses Plus Student 11,071 PointsHey Stefan Mach,
almost there! You created a property called shoppingList
in your interface file:
@property (nonatomic, strong) NSArray *shoppingList;
We want this property to contain the shopping list objects, like toothpaste etc. In you viewDidLoad
code however, you are not initializing this property with the given objects, instead you are allocating and initializing a new NSArray
called shopping list:
NSArray *shoppingList = [[NSArray alloc] initWithObjects: @"toothpaste", @"bread", @"eggs", nil];
If you wanted to use the existing property, code would be as follows:
self.shoppingList = [[NSArray alloc] initWithObjects: @"toothpaste", @"bread", @"eggs", nil];
Hope that helps :)
Stefan Mach
3,691 PointsStefan Mach
3,691 PointsThank you. It did.