Why You’re Not Supposed to Call Swift’s description
However, you should absolutely not use the following pattern, where a function argument is constrained to
Custom[Debug]StringConvertible, either with a generic constraint or a plain type specification[…][…]
Instead, the function should accept any type, because anything is printable:
func doSomething3<T>(with x: T) { // ... // Call String(describing: x) }[…]
When you rely on
LosslessStringConvertiblesemantics, you should absolutely access thedescriptionproperty directly, despite the above advice to the contrary. As we have seen, the alternativeString(describing:)prefersTextOutputStreamable’s representation overdescriptionif it’s available, and you can’t be 100 % certain that representation is identical to the value’sdescription, however unlikely any differences are.