Last active
November 23, 2022 10:51
-
-
Save anirudhamahale/0d4a087bac35f502180b6e83998817ee to your computer and use it in GitHub Desktop.
Network Helper Extensions
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 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