Created
January 5, 2021 13:20
-
-
Save shaps80/ec693d67ad0b6d420dfc450fc82d7b05 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Encodable { | |
var debugJson: String { | |
(try? JSONEncoder().encode(self).debugJson) ?? "" | |
} | |
} | |
extension Data { | |
var debugJson: String { | |
String(decoding: self, as: UTF8.self) | |
} | |
} | |
/* | |
Demo: | |
struct Name: Encodable { | |
var first: String | |
var last: String | |
} | |
print(Name(first: "Shaps", last: "Benkau").debugJson) | |
// { "first": "Shaps", "last": "Benkau" } | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment