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

What is wrong with my code??

I added everything showed in the previous video and i keep getting the bummer message

ViewController.h
#import "UIViewController.h"

@interface ViewController : UIViewController

@property (nomatic, strong) NSArray *shoppingList;

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

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    // Add your code below!

    NSArray *shoppingList = [[NSArray alloc] initWithObjects:@"nomatic", @"strong", nil];
    self.shoppingList.text = @"Let's go grocery shopping";

}

@end

2 Answers

Christopher Augg
Christopher Augg
21,223 Points

Dylan,

  • You removed the NSString for shopping cart. You will need that back.
  • You have a typo in your property. nomatic should be nonatomic
#import "UIViewController.h"

@interface ViewController : UIViewController

@property (strong, nonatomic) NSString *shoppingCart;

@property (strong, nonatomic) NSArray *shoppingList;

@end
  • You should not use NSArray *shoppingList = ... in ViewController.m as you already have the property in the ViewController.h file. You should use self.shoppingList = ... to initialize it.
  • You want to assign the string you get from the array to the NSString shoppingCart using objectAtIndex
#import "ViewController.h"

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

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

}

@end

Hope this helps.

Regards,

Chris

This is helpful but why doesn't the video track or teach what it is that we'll be quizzed on?

Christopher Augg
Christopher Augg
21,223 Points

Lester,

I had to go back over the video as it has been a while since I last viewed it. I see what you mean as the last video prior to this challenge does not go over properties. I believe the intention of this challenge is to make sure that we are retaining fundamentals from previous videos as well. Please look back at the following course videos on properties:

In the video prior to this challenge, Pasan just made an NSArray in the implementation file ( .m ). However, the challenge is asking us to do it differently by separating the implementation ( .m ) of the NSArray from its declaration ( .h ). Once we understand properties, it becomes more clear how we can achieve what is being asked of us. Please let me know if there is anything I can do to help you further.

Regards,

Chris

Brayden Kness
Brayden Kness
12,492 Points
@property (nomatic, strong) NSArray *shoppingList;

Should be...

@property (nonatomic, strong) NSArray *shoppingList;

The array needs to be initialized with @"toothpaste" @"bread" @"eggs"

Lastly the string self.shoppingList needs to be set to @"eggs" but using the objectAtIndex: function on the array