Created
January 28, 2018 08:52
-
-
Save soapyigu/7551a077e677a9c8cb8deae8890adc1a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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