开发者

NSNumber: stringValue crashes, description works

开发者 https://www.devze.com 2023-03-30 09:46 出处:网络
[measureValue stringVal开发者_运维知识库ue] gives me this exception: Terminating app due to uncaught exception \'NSInvalidArgumentException\', reason: \'-[NSCFString stringValue]: unrecognized selec

[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.

0

精彩评论

暂无评论...
验证码 换一张
取 消