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
Gurmokh Sangha
1,578 PointsRefactoring code challenge 2
Hi Guys,
I'm seriously stuck on question 2 of the refactoring challenge. I 've tried the below code and variations of. I"m not sure what i'm doing wrong, Help would be much appreciated
import "Quote.h" @implementation Quote
- (NSArray *) quotes { if(_quotes == nil){ NSArray *quotes = [[NSArray alloc]initWithObjects:@"1",@"2",@"3",nil]; } return quotes; }
(NSString *) randomQuote { int random = arc4random_uniform(self.quotes.count); return [self.quotes objectAtIndex:random]; }
@end
2 Answers
John W
21,558 PointsIn your quotes getter method, you want to initialize and return the internal variable _quotes instead of quotes. The one without the underscore is actually the getter method, not the variable.
Also, presumably, _quotes should be already defined through @property or within @interface, so you don't have to specify NSArray here.
Gurmokh Sangha
1,578 PointsThanks for the advice, I had to bounce back with the video a few times before i got it.