Strange NSNumberFormatter crash
The code is simple:
static NSNumberFo开发者_JS百科rmatter *numberFormatter = nil;
if (numberFormatter == nil) {
numberFormatter = [[NSDateFormatter alloc] init];
[numberFormatter setNumberStyle:NSNumberFormatterDecimalStyle];
}
However, it crashes on the last line:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSDateFormatter setNumberStyle:]: unrecognized selector sent to instance 0x5c378d0'
How is it possible?
Because you created an NSDateFormatter, not an NSNumberFormatter.
精彩评论