Skip to content

Instantly share code, notes, and snippets.

@soapyigu
Created January 28, 2018 08:52
Show Gist options
  • Save soapyigu/7551a077e677a9c8cb8deae8890adc1a to your computer and use it in GitHub Desktop.
Save soapyigu/7551a077e677a9c8cb8deae8890adc1a to your computer and use it in GitHub Desktop.
let dict: [Float : String] = [
18.0: "ff0000",
20.0: "00ff00",
21.0: "0000ff"
]
let encoder = JSONEncoder()
encoder.outputFormatting = [.prettyPrinted, .sortedKeys]
let encoded = try! encoder.encode(dict)
let jsonText = String(decoding: encoded, as: UTF8.self)
print(jsonText)
//[
// 21,
// "0000ff",
// 18,
// "ff0000",
// 20,
// "00ff00"
//]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment