代码很简单:
static NSNumberFormatter *numberFormatter = nil;
if (numberFormatter == nil) {
numberFormatter = [[NSDateFormatter alloc] init];
[numberFormatter setNumberStyle:NSNumberFormatterDecimalStyle];
}
然而,它在最后一行崩溃了:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSDateFormatter setNumberStyle:]: unrecognized selector sent to instance 0x5c378d0'
怎么可能?
答案 0 :(得分:4)
因为您创建了NSDateFormatter,而不是NSNumberFormatter。