public func appendInterpolation(
_ number: @autoclosure @escaping () -> Double,
format: OSLogFloatFormatting = .fixed,
align: OSLogStringAlignment = .none,
privacy: OSLogPrivacy = .auto
logger.info("\(123.123, format: .exponential)")
// > 1.231230e+02
First of all, arguments are following
@autoclosure @escaping () -> T signature. In that way, some arguments won't be computed when logs are switched off (either overall or reduced by a log level).
Secondly, formatting parameters like
.align to tune output meessages. The official
OSLogInterpolation's documentation covers more of them.
Thirdly, there are many overrides for concrete types like
UInt8/UInt16/UInt32/UInt64/etc.. I presume it speeds up either compilation or method resolution for specified types 🤔
As you can see, Swift String Interpolation is a hilarious feature that might be easily overlooked, as it feels so at home with the current implementation.
You may find a much more detailed explanation of
ExpressibleByStringInterpolation at NSHipster, which covers yet another custom interpolation type example.
Know more cases of
ExpressibleByStringInterpolation? Don't hesitate to hit me up on Twitter!
You can make anything, till next time :)