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

Laura Kirby
Laura Kirby
1,814 Points

Initialize NSArray with three NSString objects. My code works in Xcode but is not evaluated as a correct solution here.

I have tested 3 different ways to initialize the NSArray with the 3 NSString objects. All three of my implementations work in Xcode but are not considered a "solution" to the quiz question.

I also tried:

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


NSArray *shoppingList = @[@"toothpaste", @"bread", @"eggs"];

What am I missing?

#import "UIViewController.h"

@interface ViewController : UIViewController
@property(nonatomic, strong)NSArray *shoppingList; 
@property (strong, nonatomic) NSString *shoppingCart;


```#import "ViewController.h"

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    // Add your code below!
    NSArray *shoppingList = [NSArray arrayWithObjects:@"toothpaste", @"bread", @"eggs", nil];


2 Answers

Jeremy Faith
Jeremy Faith
Courses Plus Student 56,696 Points

You declared NSArray *shoppingList in the header file. In the implementation file you can access @property NSArray *shoppingList using the keyword self.

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

Hope this helps.

Laura Kirby
Laura Kirby
1,814 Points

I see, rather than accessing a property on on the view controller, I was creating a completely new NSArray and accessing items from that array. Thank you Jeremy!