Last active
October 15, 2019 23:37
-
-
Save maxchuquimia/7188b613fd503482ca9794452aad9f96 to your computer and use it in GitHub Desktop.
Log a function call with it's arguments
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
func print_args(function: String = #function, prefix: String = "", _ args: Any...) { | |
let log = function | |
.components(separatedBy: ":") | |
.enumerated() | |
.reduce(prefix.isEmpty ? "" : prefix + " ") { (log, arg1) -> String in | |
let (idx, chunk) = arg1 | |
if idx == args.count - 1 { | |
return log + "\(chunk): \(args[idx])" | |
} else if idx < args.count { | |
return log + "\(chunk): \(args[idx]), " | |
} else { | |
return log + "\(chunk)" | |
} | |
} | |
print(log) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment