0
votes

[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];
1
It crashes because NSString does not respond to stringValue. Why are you setting measureValue to a string? Set it to a NSNumber.Allyn
And you ignored the warning from your compiler about incompatible pointer types why?Adam Rosenfield

1 Answers

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

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