Last active
May 26, 2022 09:51
-
-
Save jacobsapps/b592e8ad19a9d3f0a452fe117ab67d93 to your computer and use it in GitHub Desktop.
Efficient Print for Swift
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
/// 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