Created
August 26, 2021 08:06
-
-
Save rahulsingh1101/64347099f3c867420725bff9bbe48571 to your computer and use it in GitHub Desktop.
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 prettyPrintedJSON: String? { | |
do { | |
let data: Data = try JSONSerialization.data(withJSONObject: self, options: .prettyPrinted) | |
return String(data: data, encoding: .utf8) | |
} catch _ { | |
return nil | |
} | |
} | |
var data: Data? { | |
do { | |
let jsonData = try JSONSerialization.data(withJSONObject: self, options: .prettyPrinted) | |
return jsonData | |
} catch { | |
print("dictionary to data conversion error : \(error.localizedDescription)") | |
return nil | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment