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
Matej Lukášik
27,440 PointsCreating a Data Collection Code Challenge Unsolved :-(
Can anyone help me with this code challenge? http://teamtreehouse.com/library/ios-development/build-a-simple-iphone-app-2/creating-a-data-collection/create-an-nsarray-property
It says: Now it's time to display a quote from our 'quotes' array in the 'quoteLabel'. Assign the second item from the 'quotes' array to the text property of the 'quoteLabel'. Hint: use the 'objectAtIndex' method.
Here is the code:
#import "THViewController.h"
@implementation THViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Add your code below!
// Remember the array property is called 'quotes'
// And the label property is called 'quoteLabel'
self.quotes = [[NSArray alloc] initWithObjects: @"Haters gonna hate", @"Life is simple, not easy", "Winners never quit, quitters never win", nil];
self.quoteLabel.text = [self.quotes objectAtIndex:1];
}
@end
I am having problem only with the last line of code that should assign the second item from quotes to quoteLabel. text. The Challenge won't accept it. What am I doing wrong and how should I solve this challenge?
3 Answers
Matej Lukášik
27,440 PointsHow do I initialise it with NSStrings?
John W
21,558 PointsTricky bug! Though if this was in Xcode there would've been a warning. Your bug is actually on the previous line. Check your array initWithObject. Are you initializing it with NSStrings?
Matej Lukášik
27,440 PointsOMG, thank you so much Amit! Sorry to bother you with such a banality. Let me get back on track ;-)
Amit Bijlani
Treehouse Guest TeacherAmit Bijlani
Treehouse Guest TeacherThe third string "Winners never quit.." should be prefixed with an
@symbol otherwise the compiler will not know you are creating an NSString object. It will think you are trying to create a C character array which is not the same thing.