> On Mar 16, 2017, at 3:47 PM, Itai Ferber via swift-evolution 
> <[email protected]> wrote:
> 
> [FWIW, the key ordering isn’t changing at random; JSONSerialization writes 
> keys in the order that it receives them (sorted in the order that 
> NSDictionary stores them, based on hash). If you want this to not interfere 
> with your Git repo (on a more immediate timescale), you can probably do 
> something like adding a pre-commit Git hook to lint the file as needed. But I 
> digress, this is totally off-topic.]


I've had some success passing a subclass of NSDictionary which returns a sorted 
keyEnumerator, but this is a pretty blatant hack. It's even more of a blatant 
hack because it ends up returning NSProxy wrappers around the values to ensure 
that sub-dictionaries are also sorted. I'm well aware that it will probably 
either break or give a Foundation engineer an ulcer one day, but it works for 
now.

(I too would like it if JSONSerialization and JSONEncoder had a built-in way to 
emit sorted output, but I do agree that that's not really in scope here.)

-- 
Brent Royal-Gordon
Architechies

_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to