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 Build a Simple iPhone App with Objective-C Creating a Data Model Creating a Data Collection

Stefan Mach
Stefan Mach
3,691 Points

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

ViewController.h
#import "UIViewController.h"

@interface ViewController : UIViewController

@property (strong, nonatomic) NSString *shoppingCart;

@property (nonatomic, strong) NSArray *shoppingList;

@end
ViewController.m
#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
PLUS
Martin Wildfeuer
Courses Plus Student 11,071 Points

Hey Stefan Mach,

almost there! You created a property called shoppingList in your interface file:

ViewController.h
@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:

ViewController.m
NSArray *shoppingList = [[NSArray alloc] initWithObjects: @"toothpaste", @"bread", @"eggs", nil];

If you wanted to use the existing property, code would be as follows:

ViewController.m
self.shoppingList = [[NSArray alloc] initWithObjects: @"toothpaste", @"bread", @"eggs", nil];

Hope that helps :)

Stefan Mach
Stefan Mach
3,691 Points

Thank you. It did.