开发者

String to int - cocoa, objective-c

开发者 https://www.devze.com 2022-12-19 14:00 出处:网络
I\'m trying to get a value from a NSTextField (Label) and convert it to a int... minForma开发者_如何学运维tter = [[NSNumberFormatter alloc] init];

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

 minForma开发者_如何学运维tter = [[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?


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

0

精彩评论

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