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 trialDavid Plans
2,756 PointsRandom quotes assignment seems dodgy
Hi there. I know this seems to have been covered in a previous discussion, but I can't see what I'm doing wrong. In challenge task 2 of Stage 4 (refactoring into a model) of the iOS Development track, the random quotes assignment, one's asked to create a @property called 'quotes' and then use it in the implementation. Here's my implementation:
#import "Quote.h"
@implementation Quote
-(NSArray *) quotes {
if (_quotes == nil) {
_quotes = [[NSArray alloc] initWithObjects:@"foo", @"bar", @"moo", nil];
}
return _quotes;
}
- (NSString *) randomQuote {
return [self.quotes objectAtIndex:arc4random_uniform(self.quotes.count);
}
@end
and in my header file, I have:
@interface Quote : NSObject
// Add property here
@property (nonatomic, strong) NSArray *quotes;
- (NSString *) randomQuote;
@end
Unfortunately, it just keeps saying:
Bummer! Remember to allocate and initialize the instance variable '_quotes' and return it from the method named 'quotes'.
Any ideas?
3 Answers
Holger Liesegang
50,595 PointsHi David,
you are missing the closing square bracket at the end of:
return [self.quotes objectAtIndex:arc4random_uniform(self.quotes.count)];
David Plans
2,756 PointsYup! That was it! Thanks Holger.
Liam Herbert
15,140 PointsYou have to close the square bracket, like so:
return [self.quotes objectAtIndex:arc4random_uniform(self.quotes.count)];
Hope this helps