简体   繁体   中英

“Implicit conversion loses integer precision” while getting random numbers

My plan was to get the random members of the array, therefore, I tried the solution which, firstly, generate the random number:

NSUInteger rnd = arc4random_uniform([myArray count]);

However, I got the warning "Implicit conversion loses integer precision".

How too work around that warning? Is there another way to get the random value which won't cause any warnings? I prefer only code implementations, not through the settings as several answers to the similar questions suggest.

Just change the code to the following :

NSUInteger rnd = arc4random_uniform((uint32_t) [myArray count]);

The compiler gave the warning as on your machine, NSUInteger is a typedef of 64 bits, which may not be the case for other devices. Therefore, casting it, removes the warning.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM