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

Stevan Relic
Stevan Relic
798 Points

Question 3 of this Challenge, shoppingCart = [shoppingList objectAtIndex:2]; is a mistake?

I get the system saying that I should remember that arrays start at 0, well if eggs is the 3rd array object then I should invoke object 2.

I think the error is in my syntax, could you help? I had a similar issue on question 2 as it is not the same syntax as in the video.

ViewController.h
#import "UIViewController.h"

@interface ViewController : UIViewController

@property (strong, nonatomic) NSString *shoppingCart;

@end
ViewController.m
#import "ViewController.h"

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    // Add your code below!
}

@end
Russell Warwick
Russell Warwick
1,601 Points

Could you provide the code that you entered?

Stevan Relic
Stevan Relic
798 Points

Yes, of course,

Q1: @property (strong, nonatomic) NSSArray *shoppingList; //This one was OK Q2: self.shoppingList = @[@"toothpaste", @"bread", @"eggs"]; //This one was OK Q3: shoppingCart = [shoppingList objectAtIndex:2]; // This one is wrong

Thanks a lot for your help!!!

1 Answer

Russell Warwick
Russell Warwick
1,601 Points

Okay so it looks like you need to call <p> self.shoppingCart=[self.shoppingList objectAtIndex:2]; </p>

Stevan Relic
Stevan Relic
798 Points

Hi Russell, Thanks a lot for your help. That worked, did not see the self.shoppingList had to be there!!