Skip to content

Instantly share code, notes, and snippets.

@anirudhamahale
Last active November 23, 2022 10:51
Show Gist options
  • Save anirudhamahale/0d4a087bac35f502180b6e83998817ee to your computer and use it in GitHub Desktop.
Save anirudhamahale/0d4a087bac35f502180b6e83998817ee to your computer and use it in GitHub Desktop.
Network Helper Extensions
extension Data {
func printData(with title: String?) {
if let title = title {
print(title)
}
if let json = try? JSONSerialization.jsonObject(with: self, options: .mutableContainers),
let jsonData = try? JSONSerialization.data(withJSONObject: json, options: .prettyPrinted) {
print(String(decoding: jsonData, as: UTF8.self))
} else {
String(decoding: self, as: UTF8.self)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment