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 trialCaleb Kleveter
Treehouse Moderator 37,862 PointsI've used this code before, why won't it work?
I've done this code challenge before but I had to stop part-way though, the code below is the same (as far as I can tell) but it won't work, what's wrong?
@interface Quote : NSObject
// Add property here
@property (strong, nonatomic, readonly) NSArry *quotes;
- (NSString *) randomQuote;
@end
#import "Quote.h"
@implementation Quote
- (NSString *) randomQuote {
return @"Some Quote";
}
@end
Caleb Kleveter
Treehouse Moderator 37,862 PointsThanks so much, can hardly believe I missed it :)
4 Answers
Stone Preston
42,016 Pointsyour code is almost correct, with a few minor issues (in addition to the one Carter pointed out):
you added your code to the randomQuote method, you are supposed to implement a new method. called quotes that returns an NSArray.) .
I used the code below and passed the first 2 tasks just fine
#import "Quote.h"
@implementation Quote
- (NSArray *) quotes {
if (_quotes == nil){
_quotes = [[NSArray alloc] initWithObjects:@"Happy, Happy, Happy",
@"Your gullible", @"Say cheese", nil];
}
return _quotes;
}
- (NSString *) randomQuote {
return @"Some Quote";
}
@end
and remove the read only attribute from your property. it messes up the challenge and wont accept it with it in there:
@property (strong, nonatomic) NSArray *quotes;
Caleb Kleveter
Treehouse Moderator 37,862 PointsStill isn't working, I even tried to copy and paste the code and had no luck with it.
Stone Preston
42,016 Pointsare you sure ? I just did again and passed tasks 1 and 2 using the code above. below are the full .h and .m files:
@interface Quote : NSObject
// Add property here
@property (strong, nonatomic) NSArray *quotes;
- (NSString *) randomQuote;
@end
#import "Quote.h"
@implementation Quote
- (NSArray *) quotes {
if (_quotes == nil){
_quotes = [[NSArray alloc] initWithObjects:@"Happy, Happy, Happy",
@"Your gullible", @"Say cheese", nil];
}
return _quotes;
}
- (NSString *) randomQuote {
return @"Some Quote";
}
@end
Caleb Kleveter
Treehouse Moderator 37,862 PointsYep, I checked and I can't find anything.
Stone Preston
42,016 Pointspost what you currently have implemented
Caleb Kleveter
Treehouse Moderator 37,862 Points@interface Quote : NSObject
// Add property here
@property (strong, nonatomic) NSArray *quotes;
- (NSString *) randomQuote;
@end
#import "Quote.h"
@implementation Quote
- (NSString *) randomQuote {
if (_quotes == nil){
_quotes = [[NSArray alloc] initWithObjects:@"Happy, Happy, Happy",
@"Your gullible", @"Say cheese", nil];
}
return _quotes;
}
- (NSString *) randomQuote {
return @"Some Quote";
}
@end
Stone Preston
42,016 Pointsyou have randomQuote implemented twice. you need to have a randomQuote method and a quotes method:
here is what you have:
#import "Quote.h"
@implementation Quote
//randomQuote once
- (NSString *) randomQuote {
if (_quotes == nil){
_quotes = [[NSArray alloc] initWithObjects:@"Happy, Happy, Happy",
@"Your gullible", @"Say cheese", nil];
}
return _quotes;
}
//randomQuote twice
- (NSString *) randomQuote {
return @"Some Quote";
}
@end
and here is what you should have
#import "Quote.h"
@implementation Quote
//quotes method
- (NSArray *) quotes {
if (_quotes == nil){
_quotes = [[NSArray alloc] initWithObjects:@"Happy, Happy, Happy",
@"Your gullible", @"Say cheese", nil];
}
return _quotes;
}
//random quote method
- (NSString *) randomQuote {
return @"Some Quote";
}
@end
Carter Randall
3,311 PointsCarter Randall
3,311 PointsYou are missing an 'a' in NSArray where you are declaring the property.