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 trialKyle Eames
1,873 PointsI don't understand why this doesn't work
Why doesn't this work?
return self.quotes[arc4random_uniform(self.quotes.count)];
3 Answers
agreatdaytocode
24,757 PointsTry this:
- (IBAction)buttonPressed {
int random = arc4random_uniform(self.predictions.count);
self.predictionLabel.text = [self.predictions objectAtIndex:random];
}
Kyle Eames
1,873 PointsThanks for answering. That was actually a code challenge, and it drove me up a wall because I couldn't see why that wasn't working, but if my memory serves me correctly, I had changed it to
return [self.quotes objectAtIndex: arc4random_uniform(self.predictions.count)];
and it worked. I have no idea why this worked, and the other didn't. The both say the same thing. Any ideas?
agreatdaytocode
24,757 PointsOne of them has quotes.count the other is predictions.count. Both would work, however I think the challenge is asking for the predictions.count
Kyle Eames
1,873 PointsOh, yeah! I remember now. I did get the contents of the tutorials and the code challenges confused. Thanks!