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

Eliot Ostling
Eliot Ostling
9,599 Points

Undeclared ID

I am working on challenge question 3 and it is telling me to find ShoppingList = Eggs which is 2, because index in arrays start at zero, then it wants me to store in shoppingCart but it won't allow me. How do I proceed?

ViewController.h
#import "UIViewController.h"

@interface ViewController : UIViewController

@property (strong, nonatomic) NSString *shoppingCart;
@property (strong, nonatomic) NSArray *shoppingList;


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

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
self.shoppingList = [[NSArray alloc] initWithObjects:@"toothpaste", @"bread", @"eggs", nil];

self.shoppingList.text = [shoppingList objectAtIndex:2] 



}

@end

2 Answers

Michael Hulet
Michael Hulet
47,912 Points

Pay attention to what variables you use when, and when to use the self keyword. This code should work, but compare it to your old code

-(void)viewDidLoad{
    [super viewDidLoad];
    self.shoppingList = [[NSArray alloc] initWithObjects:@"toothpaste", @"bread", @"eggs", nil];
    // Compare this line to your code, in specific
    self.shoppingCart.text = [self.shoppingList objectAtIndex:2];
}
Eliot Ostling
Eliot Ostling
9,599 Points

Thank you for your help! To my knowledge the "self" is a pointer to the current object or sometimes the instance of a class. Self is always the object receiving the method in which self is used. Correct? The code challenges always has minor nuances this is the code that passed for me! Thank you again

self.shoppingCart = [self.shoppingList objectAtIndex:2];   //No .text

Cheers!

Michael Hulet
Michael Hulet
47,912 Points

Based on your description of self, it seems like you have a relatively good understanding of it. You were just missing it in one place, but you seem to be alright now. Great job!