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])];
Share:
13,046
Admin
Author by

Admin

Updated on June 05, 2022

Comments

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