views:

121

answers:

1

I'm trying to get a value from a NSTextField (Label) and convert it to a int...

 minFormatter = [[NSNumberFormatter alloc] init];
  [minFormatter setNumberStyle:NSNumberFormatterNoStyle];
  NSNumber *minTimeValue = [minFormatter numberFromString:[NSString stringWithFormat:@"%@", [self.minTextLabel stringValue]]];
  [minFormatter release];
  int minTimeValueInt;
  minTimeValueInt = [minTimeValue intValue];
  NSLog(@"%@", minTimeValueInt);

I can't find anything wrong with it, but the NSLog returns (null) when I log the minTimeValueInt what's wrong?

+3  A: 

%@ is the format string for an object. It's interpreting minTimeValueInt as a pointer, which is apparently 0 (null). Use %d instead.

John Calsbeek
thanks, but it returns 0 when the string value is 00?
nanochrome
"00" still parses to the integer 0, which is equivalent (in this architecture) to null.
John Calsbeek
right thanks again!
nanochrome