aneuryzm
aneuryzm

Reputation: 64834

NSNumber: stringValue crashes, description works

[measureValue stringValue] 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];

Upvotes: 0

Views: 4337

Answers (1)

Terry Wilcox
Terry Wilcox

Reputation: 9040

 NSNumber *measureValue = [NSString stringWithFormat:@"%i", [cellContent integerValue]];

That line returns an NSString, not an NSNumber. You're sending stringValue to the NSString.

Upvotes: 11

Related Questions