Skip to content

Instantly share code, notes, and snippets.

@maxchuquimia
Last active October 15, 2019 23:37
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 maxchuquimia/7188b613fd503482ca9794452aad9f96 to your computer and use it in GitHub Desktop.
Save maxchuquimia/7188b613fd503482ca9794452aad9f96 to your computer and use it in GitHub Desktop.
Log a function call with it's arguments
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