Created
August 18, 2021 20:18
-
-
Save cedricbahirwe/967cf1f97d2b216b943d8de5cba24335 to your computer and use it in GitHub Desktop.
A simple helper for debugging my networking requests, response and status code😀.
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
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