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 (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,676 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.