Created
February 13, 2019 03:53
-
-
Save thexande/e70e27cdacae2b0382800e1bbdc39230 to your computer and use it in GitHub Desktop.
Convert Dictionary to JSON in Swift
This file contains 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
extension Dictionary { | |
var jsonStringRepresentaiton: String? { | |
guard let theJSONData = try? JSONSerialization.data(withJSONObject: self, | |
options: [.prettyPrinted]) else { | |
return nil | |
} | |
return String(data: theJSONData, encoding: .ascii) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment