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 (iOS7) Creating a Data Collection Create an NSArray Property

Miguel Rivera
Miguel Rivera
21,679 Points

I initialised the array, but the program said it is wrong because I have to initialize

What i have to change?

THViewController.h
#import "UIViewController.h"
#import "UILabel.h"

@interface THViewController : UIViewController

@property (nonatomic, strong) IBOutlet UILabel *quoteLabel;
@property (strong, nonatomic) NSArray *quotes;
@end
THViewController.m
#import "THViewController.h"

@implementation THViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    // Add your code below! 
    // Remember the array property is called 'quotes'
    // And the label property is called 'quoteLabel'
  NSArray *quotes = [[NSArray alloc]initWithObjects: @"Haters gonna hate", @"Life is simple, not easy",@"Winners never quit, quitters never win", nil];    

   self.quoteLabel.text = [self.quotes objectAtIndex:0];
}

@end

1 Answer

Chris Shaw
Chris Shaw
26,662 Points

Hi Miguel,

Currently your simply creating a new array and assigning it to the local scope rather than using the quotes property assigned to the class which you can access via self.

self.quotes = [[NSArray alloc] initWithObjects:@"Haters gonna hate", @"Life is simple, not easy", @"Winners never quit, quitters never win", nil];

Also your objectAtIndex method call should reference the second item which is at index 1.