Skip to content

Instantly share code, notes, and snippets.

@jacobsapps
Last active May 26, 2022 09:51
Show Gist options
  • Save jacobsapps/b592e8ad19a9d3f0a452fe117ab67d93 to your computer and use it in GitHub Desktop.
Save jacobsapps/b592e8ad19a9d3f0a452fe117ab67d93 to your computer and use it in GitHub Desktop.
Efficient Print for Swift
/// An alternative to the print function which allows for better security and efficiency in release builds.
///
/// Release configurations: do nothing.
/// Debug configurations: write the textual representations of the given items into the standard output.
///
/// - Parameters:
/// - items: Zero or more items to print.
/// - separator: A string to print between each item. The default is a single
/// space (`" "`).
/// - terminator: The string to print after all items have been printed. The
/// default is a newline (`"\n"`).
///
public func efficientPrint<T>(_ items: T..., separator: String = " ", terminator: String = "\n") {
#if DEBUG
items.forEach {
Swift.print($0, separator: separator, terminator: "")
}
Swift.print(terminator: terminator)
#endif
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment