[swift-users] Why do collections use the debugDescription on their elements?
ole at oleb.net
Thu Jan 5 10:53:16 CST 2017
> I wonder why the description method of collections use the debugDescription method to print their elements, and not the description method.
Dmitri Gribenko gave this reason in December 2015 :
> Array's description shouldn't be presented to the user in raw form,
> ever, so the use case here is debugging. Thus, it makes sense to
> present the debug representation of the elements in both cases.
> Consider an array of strings:
> var myArray = [ "", "", "" ]
> If we used the regular description, then String(myArray) would be
> "[ , , ]", which looks like a library bug.
More information about the swift-users