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


Stuck on code challenge 2/3 in how to create a class...Making a simple iPhone app

I can't figure out the problem...Here is my code

```#import "Quote.h"

@implementation Quote

  • (NSString *) randomQuote { if (_quotes == nil) { _quotes = [[NSArray alloc] initWithObjects:@"1", @"2", @"3", nil]; } return _quotes; }


4 Answers

So according to this, the quotes var is an array. The objective is to alloc/init the quotes var only if it is nil and init it with three strings of your liking.

It's really hard to read the code you have in the format that you have it, but from what I'm seeing, you're supposed to be returning a String but instead you're returning an NSArray.

These are the instructions.

Switch to the implementation file and implement a 'quotes' method which will allocate and initialize the _quotes instance variable only if it is 'nil'. Initialize the array with any three strings.

So is the _quotes var an NSArray or String?

Gareth Borcherds
Gareth Borcherds
9,372 Points

It's an nsarray with 3 nsstring objects in that array.