Read Secrets of “printf`
Today while reviewing code of my colleague I came across of this:
private func signedValueText(_ value: Int) -> String {
let sign = value > 0 ? "+" : ""
return sign + String(value)
}
Read Secrets of printf
:
In the most simple case,
printf
takes one argument: a string of characters to be printed. This string is composed of characters, each of which is printed exactly as it appears. Soprintf("xyz");
would simply print an “x”, then a “y”, and finally a “z”. This is not exactly “formatted” printing, but it is still the basis of whatprintf
does.
WRONG!