[swift-evolution] [Proposal] Foundation Swift Encoders

Brent Royal-Gordon brent at architechies.com
Fri Mar 17 15:38:57 CDT 2017


> On Mar 16, 2017, at 3:47 PM, Itai Ferber via swift-evolution <swift-evolution at swift.org> 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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170317/d7b6ae2a/attachment.html>


More information about the swift-evolution mailing list