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

iOS

Marie Veverka
Marie Veverka
12,117 Points

CrystalBall app error with randomization

Hi there! An error with my following line of code appeared in my CrystalBall.m file after I launched in on my iPhone: int random = arc4random_uniform(self.predictions.count); It says "Implicit conversion loses integer precision: 'NSUInteger' (aka 'unsigned long') to 'u_int32_t' (aka 'unsigned int'). Anyone have any idea how to fix this issue? Thanks in advance!

2 Answers

Stone Preston
Stone Preston
42,016 Points

cast your count to a 32 bit unsinged int. arc4random expects a 32 bit integer. if you are running on a 64 bit system the count variable is 64 bit integer, which makes the compiler complain. you can safely cast this to resolve the compiler warning

int random = arc4random_uniform((uint32_t)self.predictions.count);
Marie Veverka
Marie Veverka
12,117 Points

Yay! Thanks Stone, that did it! Thanks for your help too Jason. I really appreciate it. :)