Created
April 17, 2020 07:35
-
-
Save ha1f/569dc76f9c67e07b32481c606724ac56 to your computer and use it in GitHub Desktop.
Print encodable as JSON
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
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