Skip to content

Commit 01fc8d8

Browse files
committed
Use compare(_:options:range:locale:) in comparison
1 parent d6d7dc8 commit 01fc8d8

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

Foundation/NSJSONSerialization.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,11 @@ private struct JSONWriter {
531531
let b = b.key as? String else {
532532
throw NSError(domain: NSCocoaErrorDomain, code: CocoaError.propertyListReadCorrupt.rawValue, userInfo: ["NSDebugDescription" : "NSDictionary key must be NSString"])
533533
}
534-
return a < b
534+
let options: NSString.CompareOptions = [.numeric, .caseInsensitive, .forcedOrdering]
535+
let range = a.startIndex ..< a.endIndex
536+
let locale = NSLocale.systemLocale()
537+
538+
return a.compare(b, options: options, range: range, locale: locale) == .orderedAscending
535539
})
536540
for elem in elems {
537541
try serializeDictionaryElement(key: elem.key, value: elem.value)

0 commit comments

Comments
 (0)