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

Kareem Irsheid
PLUS
Kareem Irsheid
Courses Plus Student 257 Points

I do not know why I am getting this wrong. It keeps telling me to list the 3 items mentioned and I did.

It keeps telling me to list the 3 items that were mentioned and I did as well as to include the word self of which I did as well but it keeps saying there is still something wrong.

ViewController.h
#import "UIViewController.h"

@interface ViewController : UIViewController

@property (strong, nonatomic) IBOutlet UILabel NSArray *shoppingList;


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

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

(IBAction)shoppingList {

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

    self.shoppingList.text = [shoppingList objectAtIndex:strong, nonatomic]; 
}

@end

4 Answers

Caleb Kleveter
MOD
Caleb Kleveter
Treehouse Moderator 37,862 Points

Here is what I used to pass:

I create the array (step 1):

@property (nonatomic, strong) NSArray *shoppingList;

Then I add items to the array (step 2):

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

Then I add eggs to the shopping cart (step 3):

self.shoppingCart = [_shoppingList objectAtIndex:2]; 

I'm not really understanding the purpose of the "" before the NSArray shoppingList. Should the "" be used at all times to access the object shoppingList after it is initiated or are there only a few circumstances?

Caleb Kleveter
MOD
Caleb Kleveter
Treehouse Moderator 37,862 Points

I'm having trouble understanding the question. Can you try re-wording it?

I guess underscores don't get submitted in questions...But, my question is why is it that there has to be an underscore before shoppingList.

Caleb Kleveter
Caleb Kleveter
Treehouse Moderator 37,862 Points

I am not sure why. All I know is 'NSArray *shoppingList' and 'self.shoppingList' didn't work for me.

Stephen Wall
PLUS
Stephen Wall
Courses Plus Student 27,294 Points
#import "ViewController.h"

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    // Add your code below!                                index 0    index 1      index 2
  self.shoppingList = [[NSArray alloc] initWithObjects: @"toothpaste", @"bread", @"eggs", nil]; 
  self.shoppingCart = [self.shoppingList objectAtIndex: 2];  // See Below!!
}

@end

You are just saying: For the string shoppingCart, assign the value that is the object at index 2 of the array shoppingList : which is the eggs.