Skip to content

Instantly share code, notes, and snippets.

@cedricbahirwe
Created August 18, 2021 20:18
Show Gist options
  • Save cedricbahirwe/967cf1f97d2b216b943d8de5cba24335 to your computer and use it in GitHub Desktop.
Save cedricbahirwe/967cf1f97d2b216b943d8de5cba24335 to your computer and use it in GitHub Desktop.
A simple helper for debugging my networking requests, response and status code😀.
class DebuggingResource: NSObject {
private static func printLine(_ line: String) {
print("--- \(line) ---")
}
public static func logJsonDataFormat(_ data: Data) {
printLine("Start Debugging Json Format")
if let json = try? JSONSerialization.jsonObject(with: data) {
print(json)
} else {
print("Can not log the json")
}
printLine("End Debugging Json Format")
}
public static func logJsonDataFormat(_ data: Data, code: Int) {
printLine("Status code: \(code)")
logJsonDataFormat(data)
}
public static func logError(_ message: Error, from origin: String) {
}
public static func logMessage(_ message: String, from origin: String? = nil) {
if let origin = origin {
printLine("Message from \(origin)")
printLine(message)
} else {
printLine(message)
}
}
public static func logContent(_ values: Any...) {
printLine("Start Logging Content")
values.forEach { print($0) }
printLine("End Logging Content")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment