Sometimes when I try to cover NSNumber to NSString I am getting crash. But unfortunately I am unable to debug Xcode's crash log, and I am not sure exactly what value is causing the crash. Here is crash log of Xcode. Please let me know what additional check I should do to fix the crash.
-[NSNumberFormatter _regenerateFormatter]
-[NSNumberFormatter stringForObjectValue:]
if ([value isKindOfClass:[NSNumber class]]) {
NSNumberFormatter *formatter = [NSNumberFormatter new];
NSString *string = [formatter stringFromNumber:value]; // crash
string = [string stringByReplacingOccurrencesOfString:@"," withString:@"."];
return string;
} else {
return nil;
}
Thread 0 name:
Thread 0 Crashed:
0 libicucore.A.dylib 0x00000001801acdf0 ulocimp_getKeywordValue + 204 (uloc.cpp:776)
1 libicucore.A.dylib 0x00000001801accc8 uloc_getKeywordValue + 112 (uloc.cpp:734)
2 libicucore.A.dylib 0x00000001801a1de0 ucurr_forLocale + 192 (ucurr.cpp:526)
3 libicucore.A.dylib 0x000000018022be84 icu::DecimalFormatSymbols::initialize(icu::Locale const&, UErrorCode&, signed char, icu::NumberingSystem const*) + 1264 (dcfmtsym.cpp:489)
4 libicucore.A.dylib 0x000000018022c1fc icu::DecimalFormatSymbols::DecimalFormatSymbols(icu::Locale const&, UErrorCode&) + 324 (dcfmtsym.cpp:110)
5 libicucore.A.dylib 0x000000018033a978 unum_open + 396 (unum.cpp:75)
6 CoreFoundation 0x000000018043f088 __cficu_unum_open + 64 (CFICULogging.c:2292)
7 CoreFoundation 0x000000018045d60c CFNumberFormatterCreate + 276 (CFNumberFormatter.c:129)
8 Foundation 0x0000000181c5477c -[NSNumberFormatter _regenerateFormatter] + 236 (NSNumberFormatter.m:270)
9 Foundation 0x0000000181c35a74 -[NSNumberFormatter stringForObjectValue:] + 344 (NSNumberFormatter.m:708)
10 ProjectName 0x0000000102267918 -[My method] + 184
The issue seems to be related to iOS 12.x and it is still active. You can fix the problem by using following:
[@(value.integerValue) stringValue]