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