You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is a workaround rather than a full fix.
- NSNumber(value: UInt.max).stringValue was returning "-1"
instead of "18446744073709551615" because NSNumber holds any
value > Int64.max as a 128Bit quantity using a high Int and
low UInt. It marks this type as an 'SInt128Type'.
- CFNumberFormatterCreateStringWithNumber() uses CFNumberGetType()
to get this type however CoreFoundation wants to hide SInt128Type
(probably for backwards compatibilty) and instead returns it
as an SInt64Type. Thus only the low part of the NSNumber is used
for the number and this is interpreted as an Int64.
- The workaround is simply in NSNumber.description(withLocale:)
to test to see if the value is of type SInt128Type and if so
use String(format: "%@") to convert it to a string instead of
using CFNumberFormatterCreateStringWithNumber(). This should be
ok for most situations since it is only used for positive
integers and there are no issues with formatting leading zeros
or decimal points.
- For JSONWriter._serializationString(for: NSNumber) the value
is tested to see if it is not a floating point value and if so
the .stringValue method is used to create a string.
- NSNumber.description(withLocale:) - cache the CFNumberFormatter
when locale is nil as a small speedup.
0 commit comments