Created
September 19, 2021 16:56
-
-
Save joshuajhomann/d8706fd05a47986b9ba3bd5233c098a8 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
struct A: Codable { | |
var a = "test" | |
var b = 1 | |
} | |
private extension Encodable { | |
var prettyPrinted: String { | |
let encoder = JSONEncoder() | |
encoder.outputFormatting = [.prettyPrinted, .sortedKeys] | |
return (try? encoder.encode(self)) | |
.flatMap { String(data: $0, encoding: .utf8) } ?? "\(self)" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment