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

General Discussion Build a Simple iPhone App (iOS7) Creating a Data Collection Create an NSArray Property

NSArray quotes

Hey. Im at the NSArray quotes challenge, and I cant get it to work. I tried rewatching the video, but i cant get it to work.

the .m file #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 self.quotes *quotes = [[NSArray alloc]initWithObjects:@"Haters gonna hate", @"Life is simple, not easy", @"Winners never quit, quitters never win", nil]; }

@end

the .h file

#import "UIViewController.h"

import "UILabel.h"

@interface THViewController : UIViewController @property (nonatomic, strong) NSArray *quotes; @property (nonatomic, strong) IBOutlet UILabel *quoteLabel;

@end

1 Answer

The problem is in viewDidLoad. You are initializing it the way you would declare it. You can remove the NSArray and *quotes from the line and it'll work.

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

This is because you have already declared a NSArray @property named quotes in the header file. When you do this, Xcode automatically creates an instance variable named quotes, so you don't need to create it again. See this answer for more about setters, getters and properties.

That makes sense :) Thank you