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 trial7 Answers
Stone Preston
42,016 Pointsnot really sure why your code isnt working. Everything looks good. Here is the implementation file that worked for me:
#import "Quote.h"
@implementation Quote
- (NSString *) randomQuote {
return @"Some Quote";
}
- (NSArray *)quotes {
if (_quotes == nil) {
_quotes = [[NSArray alloc] initWithObjects:@"a", @"b", @"c", nil];
}
return _quotes;
}
@end
Stone Preston
42,016 Pointsyour method looks right to me. this is what I passed it with
- (NSArray *)quotes {
if (_quotes == nil) {
_quotes = [[NSArray alloc] initWithObjects:@"a", @"b", @"c", nil];
}
return _quotes;
}
Stone Preston
42,016 Pointshere is the .h file
@interface Quote : NSObject
// Add property here
@property (nonatomic, strong) NSArray *quotes;
- (NSString *) randomQuote;
@end
Peter Hearne
6,803 Pointsthis is what i was asked.. Switch to the implementation file and implement a 'quotes' method which will allocate and initialize the _quotes instance variable only if it is 'nil'. Initialize the array with any three strings.
this is the code i wrote and it said it is incorrect
- (NSArray *) quotes { if (_quotes == nil){ _quotes = [[NSArray alloc] initWithObjects:@"It is Certain", @"It is Decidedly so", @"The answer is in your heart", nil]; } return _quotes; }
Peter Hearne
6,803 Pointsstill not passing through :/ my whole page looks like this... "
import "Quote.h"
@implementation Quote
-
(NSArray *)quotes {
if (_quotes == nil) {
_quotes = [[NSArray alloc] initWithObjects:@"a", @"b", @"c", nil];
}
return _quotes; }
-
(NSString *) randomQuote {
return @"Some Quote"; }
@end"
Peter Hearne
6,803 Pointshmm can i see your quote.h file please
Peter Hearne
6,803 Pointsthank you so much it is working now, for some reason it was because i had the property " readonly"
Riley Hilliard
Courses Plus Student 17,771 PointsRiley Hilliard
Courses Plus Student 17,771 PointsWhat is the question?