Search code examples
iosnsnumber

__NSCFNumber return negative value


For some reason i cant set my NSNumber value.

Code is simple:

    obj.objectId = [filteredArr[i] valueForKey:@"idx"];

Where [[filteredArr[i] valueForKey:@"idx"] class] is __NSCFNumber.

It should be a number from 0 to 200.. but it is actually -5764607523034234861


Solution

  • NSNumber and NSString respond to the methods -intValue which returns an int.

    NSNumber *myNumber = @([[filteredArr[i] valueForKey:@"idx"]intValue]); 
    

    This may help you.