@@ -183,7 +183,7 @@ open class JSONSerialization : NSObject {
183
183
return value
184
184
}
185
185
throw NSError ( domain: NSCocoaErrorDomain, code: CocoaError . propertyListReadCorrupt. rawValue, userInfo: [
186
- " NSDebugDescription " : " JSON text did not start with array or object and option to allow fragments not set. "
186
+ NSDebugDescriptionErrorKey : " JSON text did not start with array or object and option to allow fragments not set. "
187
187
] )
188
188
}
189
189
@@ -353,7 +353,7 @@ private struct JSONWriter {
353
353
let num = __SwiftValue. store ( obj) as! NSNumber
354
354
writer ( num. description)
355
355
default :
356
- throw NSError ( domain: NSCocoaErrorDomain, code: CocoaError . propertyListReadCorrupt. rawValue, userInfo: [ " NSDebugDescription " : " Invalid object cannot be serialized " ] )
356
+ throw NSError ( domain: NSCocoaErrorDomain, code: CocoaError . propertyListReadCorrupt. rawValue, userInfo: [ NSDebugDescriptionErrorKey : " Invalid object cannot be serialized " ] )
357
357
}
358
358
}
359
359
@@ -390,7 +390,7 @@ private struct JSONWriter {
390
390
391
391
private func serializeFloat< T: FloatingPoint & LosslessStringConvertible > ( _ num: T ) throws {
392
392
guard num. isFinite else {
393
- throw NSError ( domain: NSCocoaErrorDomain, code: CocoaError . propertyListReadCorrupt. rawValue, userInfo: [ " NSDebugDescription " : " Invalid number value ( \( num) ) in JSON write " ] )
393
+ throw NSError ( domain: NSCocoaErrorDomain, code: CocoaError . propertyListReadCorrupt. rawValue, userInfo: [ NSDebugDescriptionErrorKey : " Invalid number value ( \( num) ) in JSON write " ] )
394
394
}
395
395
var str = num. description
396
396
if str. hasSuffix ( " .0 " ) {
@@ -460,7 +460,7 @@ private struct JSONWriter {
460
460
if let key = key as? String {
461
461
try serializeString ( key)
462
462
} else {
463
- throw NSError ( domain: NSCocoaErrorDomain, code: CocoaError . propertyListReadCorrupt. rawValue, userInfo: [ " NSDebugDescription " : " NSDictionary key must be NSString " ] )
463
+ throw NSError ( domain: NSCocoaErrorDomain, code: CocoaError . propertyListReadCorrupt. rawValue, userInfo: [ NSDebugDescriptionErrorKey : " NSDictionary key must be NSString " ] )
464
464
}
465
465
pretty ? writer ( " : " ) : writer ( " : " )
466
466
try serializeJSON ( value)
@@ -470,7 +470,7 @@ private struct JSONWriter {
470
470
let elems = try dict. sorted ( by: { a, b in
471
471
guard let a = a. key as? String ,
472
472
let b = b. key as? String else {
473
- throw NSError ( domain: NSCocoaErrorDomain, code: CocoaError . propertyListReadCorrupt. rawValue, userInfo: [ " NSDebugDescription " : " NSDictionary key must be NSString " ] )
473
+ throw NSError ( domain: NSCocoaErrorDomain, code: CocoaError . propertyListReadCorrupt. rawValue, userInfo: [ NSDebugDescriptionErrorKey : " NSDictionary key must be NSString " ] )
474
474
}
475
475
let options : NSString . CompareOptions = [ . numeric, . caseInsensitive, . forcedOrdering]
476
476
let range : Range < String . Index > = a. startIndex..< a. endIndex
@@ -593,7 +593,7 @@ private struct JSONReader {
593
593
594
594
guard let chunk = String ( data: Data ( bytes: buffer. baseAddress!. advanced ( by: begin) , count: byteLength) , encoding: encoding) else {
595
595
throw NSError ( domain: NSCocoaErrorDomain, code: CocoaError . propertyListReadCorrupt. rawValue, userInfo: [
596
- " NSDebugDescription " : " Unable to convert data to a string using the detected encoding. The data may be corrupt. "
596
+ NSDebugDescriptionErrorKey : " Unable to convert data to a string using the detected encoding. The data may be corrupt. "
597
597
] )
598
598
}
599
599
return chunk
@@ -627,7 +627,7 @@ private struct JSONReader {
627
627
switch self . source. takeASCII ( input) {
628
628
case nil :
629
629
throw NSError ( domain: NSCocoaErrorDomain, code: CocoaError . propertyListReadCorrupt. rawValue, userInfo: [
630
- " NSDebugDescription " : " Unexpected end of file during JSON parse. "
630
+ NSDebugDescriptionErrorKey : " Unexpected end of file during JSON parse. "
631
631
] )
632
632
case let ( taken, index) ? where taken == ascii:
633
633
return index
@@ -686,22 +686,22 @@ private struct JSONReader {
686
686
}
687
687
else {
688
688
throw NSError ( domain: NSCocoaErrorDomain, code: CocoaError . propertyListReadCorrupt. rawValue, userInfo: [
689
- " NSDebugDescription " : " Invalid escape sequence at position \( source. distanceFromStart ( currentIndex) ) "
689
+ NSDebugDescriptionErrorKey : " Invalid escape sequence at position \( source. distanceFromStart ( currentIndex) ) "
690
690
] )
691
691
}
692
692
default :
693
693
currentIndex = index
694
694
}
695
695
}
696
696
throw NSError ( domain: NSCocoaErrorDomain, code: CocoaError . propertyListReadCorrupt. rawValue, userInfo: [
697
- " NSDebugDescription " : " Unexpected end of file during string parse. "
697
+ NSDebugDescriptionErrorKey : " Unexpected end of file during string parse. "
698
698
] )
699
699
}
700
700
701
701
func parseEscapeSequence( _ input: Index ) throws -> ( String , Index ) ? {
702
702
guard let ( byte, index) = source. takeASCII ( input) else {
703
703
throw NSError ( domain: NSCocoaErrorDomain, code: CocoaError . propertyListReadCorrupt. rawValue, userInfo: [
704
- " NSDebugDescription " : " Early end of unicode escape sequence around character "
704
+ NSDebugDescriptionErrorKey : " Early end of unicode escape sequence around character "
705
705
] )
706
706
}
707
707
let output : String
@@ -741,7 +741,7 @@ private struct JSONReader {
741
741
// Trail surrogate must come after lead surrogate
742
742
throw CocoaError . error ( . propertyListReadCorrupt,
743
743
userInfo: [
744
- " NSDebugDescription " : """
744
+ NSDebugDescriptionErrorKey : """
745
745
Unable to convert unicode escape sequence (no high-surrogate code point) \
746
746
to UTF8-encoded character at position \( source. distanceFromStart ( input) )
747
747
"""
@@ -752,7 +752,7 @@ private struct JSONReader {
752
752
UTF16 . isTrailSurrogate ( trailCodeUnit) else {
753
753
throw CocoaError . error ( . propertyListReadCorrupt,
754
754
userInfo: [
755
- " NSDebugDescription " : """
755
+ NSDebugDescriptionErrorKey : """
756
756
Unable to convert unicode escape sequence (no low-surrogate code point) \
757
757
to UTF8-encoded character at position \( source. distanceFromStart ( input) )
758
758
"""
@@ -852,7 +852,7 @@ private struct JSONReader {
852
852
guard nextASCII ( ) else { return true }
853
853
} else {
854
854
throw NSError ( domain: NSCocoaErrorDomain, code: CocoaError . propertyListReadCorrupt. rawValue,
855
- userInfo: [ " NSDebugDescription " : " Numbers must start with a 1-9 at character \( input) . " ] )
855
+ userInfo: [ NSDebugDescriptionErrorKey : " Numbers must start with a 1-9 at character \( input) . " ] )
856
856
}
857
857
858
858
if ascii == JSONReader . DECIMAL_SEPARATOR {
@@ -861,7 +861,7 @@ private struct JSONReader {
861
861
guard nextASCII ( ) else { return true }
862
862
} else if JSONReader . allDigits. contains ( ascii) {
863
863
throw NSError ( domain: NSCocoaErrorDomain, code: CocoaError . propertyListReadCorrupt. rawValue,
864
- userInfo: [ " NSDebugDescription " : " Leading zeros not allowed at character \( input) . " ] )
864
+ userInfo: [ NSDebugDescriptionErrorKey : " Leading zeros not allowed at character \( input) . " ] )
865
865
}
866
866
867
867
digitCount = string. count - ( isInteger ? 0 : 1 ) - ( isNegative ? 1 : 0 )
@@ -982,17 +982,17 @@ private struct JSONReader {
982
982
func parseObjectMember( _ input: Index , options opt: JSONSerialization . ReadingOptions ) throws -> ( String , Any , Index ) ? {
983
983
guard let ( name, index) = try parseString ( input) else {
984
984
throw NSError ( domain: NSCocoaErrorDomain, code: CocoaError . propertyListReadCorrupt. rawValue, userInfo: [
985
- " NSDebugDescription " : " Missing object key at location \( source. distanceFromStart ( input) ) "
985
+ NSDebugDescriptionErrorKey : " Missing object key at location \( source. distanceFromStart ( input) ) "
986
986
] )
987
987
}
988
988
guard let separatorIndex = try consumeStructure ( Structure . NameSeparator, input: index) else {
989
989
throw NSError ( domain: NSCocoaErrorDomain, code: CocoaError . propertyListReadCorrupt. rawValue, userInfo: [
990
- " NSDebugDescription " : " Invalid separator at location \( source. distanceFromStart ( index) ) "
990
+ NSDebugDescriptionErrorKey : " Invalid separator at location \( source. distanceFromStart ( index) ) "
991
991
] )
992
992
}
993
993
guard let ( value, finalIndex) = try parseValue ( separatorIndex, options: opt) else {
994
994
throw NSError ( domain: NSCocoaErrorDomain, code: CocoaError . propertyListReadCorrupt. rawValue, userInfo: [
995
- " NSDebugDescription " : " Invalid value at location \( source. distanceFromStart ( separatorIndex) ) "
995
+ NSDebugDescriptionErrorKey : " Invalid value at location \( source. distanceFromStart ( separatorIndex) ) "
996
996
] )
997
997
}
998
998
@@ -1023,7 +1023,7 @@ private struct JSONReader {
1023
1023
}
1024
1024
}
1025
1025
throw NSError ( domain: NSCocoaErrorDomain, code: CocoaError . propertyListReadCorrupt. rawValue, userInfo: [
1026
- " NSDebugDescription " : " Badly formed array at location \( source. distanceFromStart ( index) ) "
1026
+ NSDebugDescriptionErrorKey : " Badly formed array at location \( source. distanceFromStart ( index) ) "
1027
1027
] )
1028
1028
}
1029
1029
}
0 commit comments