XCode warning : Initialization makes pointer from integer without a cast (while trying to assign a value to a NSNumber)
13,046
NSNumber is an objc object, while an int or float isn't. You're now assigning an int/float to a pointer, which isn't quite right.
Try:
// if the result is an int:
NSNumber *randomNumber = [NSNumber numberWithInt: (arc4random() % [array count])];
// if the result is a float:
NSNumber *randomNumber = [NSNumber numberWithFloat: (arc4random() % [array count])];
![Admin](/assets/logo_square_200-5d0d61d6853298bd2a4fe063103715b4daf2819fc21225efa21dfb93e61952ea.png)
Author by
Admin
Updated on June 05, 2022Comments
-
Admin about 2 years
I'm stuck with a warning in Xcode while trying to develop a small iPhone App. I've got this piece of code in Xcode :
NSNumber *randomNumber = arc4random() % [array count];
If I NSLog randomNumber, everything seems to work but Xcode keeps warning me, saying :
Initialization makes pointer from integer without a cast
There must be something I didn't understand. Thanks in advance for helping me out :)