Last active
March 29, 2019 14:23
-
-
Save dkw5877/e13d4bb230a2f70b2466161e02d69457 to your computer and use it in GitHub Desktop.
Key Encoding in Swift
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 object = ["key1":"bengal tiger", "key2":"siberian tiger", "key3":"white rhino", "key4":"african elephant"] | |
let encoder = JSONEncoder() | |
encoder.outputFormatting= .prettyPrinted | |
let encoded = try? encoder.encode(object) | |
print(String(data: encoded!, encoding: .utf8)!) | |
//output | |
{ | |
"key3" : "white rhino", | |
"key1" : "bengal tiger", | |
"key4" : "african elephant", | |
"key2" : "siberian tiger" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment