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 trialJulio Pech Constantino
1,064 PointsAm i wrong? quiz
it asks you to set the quote to 3 quotes only if _quotes is 'nil', i don't understand why this is wrong...
import "Quote.h"
@implementation Quote
-
(NSString *) randomQuote {
return @"Some Quote"; }
(NSArray *) quotes{ if (_quotes = nil){ _quotes = [[NSArray alloc] initWithObjects: @"quote 1", @"quote 2",@"quote 3", nil]; } return _quotes; }
@end
1 Answer
Robert Bojor
Courses Plus Student 29,439 PointsFirst you need to add the @property in the header file:
@property (strong, nonatomic) NSArray *quotes;
Next you need to move to the implementation file and create the quotes method that returns the array...
- (NSArray *)quotes {
if (_quotes == nil) {
_quotes = [[NSArray alloc] initWithObjects:@"Quote 1", @"Quote 2", @"Quote 3", nil];
}
return _quotes;
}
and last, change the randomQuote in the implementation file to return one of the quotes randomly using arc4random_uniform() and passing it [_quotes count] as a max rand.
- (NSString *) randomQuote {
return [_quotes objectAtIndex:arc4random_uniform([_quotes count])];
}