NSNumber: stringValue crashes, description works
[measureValue stringVal开发者_运维知识库ue]
gives me this exception:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString stringValue]: unrecognized selector sent to instance 0x4dde570'
[measureValue description]
works perfectly
But I think I should use stringValue
in the code, right?
This is the code:
NSNumber *measureValue = [NSString stringWithFormat:@"%i", [cellContent integerValue]];
//if imperial (inches)
if ([[[NSUserDefaults standardUserDefaults] stringForKey:@"Measure"] isEqualToString:@"Imperial"] ) {
//if height
if ([currentQuestion isEqualToString:@"Height"]) {
measureValue = [NSNumber numberWithDouble:(2.54 * [measureValue doubleValue])];
//elseif weight
} else {
measureValue = [NSNumber numberWithDouble:(0.45359237 * [measureValue doubleValue])];
}
//NSLog(@"%@", [measureValue stringValue]);
cellContent = [measureValue description];
NSNumber *measureValue = [NSString stringWithFormat:@"%i", [cellContent integerValue]];
That line returns an NSString, not an NSNumber. You're sending stringValue to the NSString.
精彩评论