Skip to content

Instantly share code, notes, and snippets.

@ha1f
Created April 17, 2020 07:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ha1f/569dc76f9c67e07b32481c606724ac56 to your computer and use it in GitHub Desktop.
Save ha1f/569dc76f9c67e07b32481c606724ac56 to your computer and use it in GitHub Desktop.
Print encodable as JSON
private func _jsonSerialization(from encodable: Encodable) throws -> String {
let jsonEncoder = JSONEncoder()
jsonEncoder.outputFormatting = .prettyPrinted
let encodedData = try jsonEncoder.encode(config)
return String(data: encodedData, encoding: .utf8)!
}
func prettyPrint(_ encodable: Encodable) {
do {
print(try _jsonSerialization(from: encodable))
} catch {
print(error.localizedDescription)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment