I am doing some iOS learning and I have an NSNumber which appears to be in order but when I ask for the doubleValue of it, I get null.
[stack addObject: [NSNumber numberWithDouble:operand]]
id topOfStack = [stack lastObject];
if([topOfStack isKindOfClass:[NSNumber class]]){
NSLog(@"%@",topOfStack);
NSLog(@"%@",[topOfStack class]);
result = [topOfStack doubleValue];
NSLog(@"%@",result);
}
This prints:
2012-04-11 17:52:04.909 RPNCalc[4127:f803] 3
2012-04-11 17:52:04.910 RPNCalc[4127:f803] __NSCFNumber
2012-04-11 17:52:04.910 RPNCalc[4127:f803] (null)
Why would the doubleValue come out as null?
You are getting NULL because %@ is the string literal for an object. Doubles are not objects. Use %f to NSLog a float or double.