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

Creating a Custom Class- Code Challenge

Tried, but can seem to understand the problem need help!!!!

13 Answers

Can you please be more specific with you problem? copy/paste the question in here and perhaps the code you tried to use as well.

but i need task 1

Hi can you still help me on task 1 and 3

Sure send me a link to the challenge :)

I mean post the link here lol.

Well i just found out what task 1 was!!!

Here's the link i need help on task 3..

http://teamtreehouse.com/library/creating-a-custom-class

:) awesome it was part of 2 right?

Help!

I know I posting all parts for others that come and search for answers :)

ok

Part one.

@interface Quote : NSObject

// Add property here

@property (strong, nonatomic) NSArray *quotes;

- (NSString *) randomQuote;

@end

I already got that need help on part 3

Part 2

@implementation Quote

- (NSArray *) quotes {
    if (_quotes == nil){
      _quotes = [[NSArray alloc] initWithObjects:@"One", @"two", @"three", nil];
    }
    return _quotes;
}

- (NSString *) randomQuote {

    return @"Some Quote";
}

@end

Part Three

- (NSString *) randomQuote {
int random = arc4random_uniform(self.quotes.count); //Add this line
    return [self.quotes objectAtIndex:random]; //Add this line too its in the last mins of the video
}

@end

Still not working can u just copy and paste the entire page of code!

Jose I don't have a Crystal ball that allows me to read your code. Please post it if you want help.

I meant can you copy your code Not mine!

@implementation Quote

- (NSArray *) quotes {
    if (_quotes == nil){
      _quotes = [[NSArray alloc] initWithObjects:@"One", @"two", @"three", nil];
    }
    return _quotes;
}

- (NSString *) randomQuote {
int random = arc4random_uniform(self.quotes.count); //Add this line
    return [self.quotes objectAtIndex:random]; //Add this line too its in the last mins of the video
}

@end

This is part three from top to bottom. If you can't get this to work, I suggest watching the video again.

Still not working ok ill watch it

If its not working you are missing something post your code.

import "Quote.h"

@implementation Quote

(NSArray *) quotes { if (_quotes == nil){ _quotes = [[NSArray alloc] initWithObjects:@"One", @"two", @"three", nil]; } return _quotes; }

(NSString *) randomQuote { int random = arc4random_uniform(self.quotes.count); //Add this line return [self.quotes objectAtIndex:random]; //Add this line too its in the last mins of the video }

@end

LOL add the follow to the very top.

import "Quote.h"

its already there

your code does not have dashes next to NSArray or the NSString look at the code I posted.

tried it still not working

are you posting it under the .h file or .m file?

.h file

I meant .m file

OK, look here young grasshopper, the first part is for the .h 2 and 3 go under .m

I don't know whats wrong. Try typing it in, maybe copy and paste is throwing it off?

well idk either Thanks anyway!

you can also try taking out my comments //add... //add..

i did

Ill post images maybe that will help you?

Part1

Part1

Part1