views:

4382

answers:

1

Hi all,

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 :)

+5  A: 

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])];
MathieuK

related questions