<div dir="ltr">Optional is already CustomStringConvertible. Again, this was done on purpose (that's not an argument to keep it this way, though). <a href="https://github.com/apple/swift/blob/master/stdlib/public/core/Optional.swift#L260">Source</a></div><br><div class="gmail_quote"><div dir="ltr">On Wed, May 18, 2016 at 6:33 PM David Sweeris via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">We could make Optional conform to CustomStringConvertible:<br>
var description: String {<br>
switch self {<br>
case .some(let x): return "\(x)"<br>
case .none: return "\(Wrapped.self)?.none"<br>
}<br>
}<br>
<br>
- Dave Sweeris<br>
<br>
> On May 18, 2016, at 15:56, Michael Peternell via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:<br>
><br>
> Well, I wouldn't deprecate them.<br>
><br>
> Maybe it should print something different: the value itself if it is not nil, and "nil" otherwise?<br>
><br>
> Or there may be an optional warning for this case.<br>
><br>
> Or maybe both. But not just deprecate the feature altogether. It will make people use the "!" instead in unsafe places (like "\(someOptional!)") - it's better not to crash and print something strange instead. Especially when in production.<br>
><br>
> -Michael<br>
><br>
>> Am 18.05.2016 um 20:50 schrieb Krystof Vasa via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>>:<br>
>><br>
>> The string interpolation is one of the strong sides of Swift, but also one of its weaknesses.<br>
>><br>
>> It has happened to me more than once that I've used the interpolation with an optional by mistake and the result is then far from the expected result.<br>
>><br>
>> This happened mostly before Swift 2.0's guard expression, but has happened since as well.<br>
>><br>
>> The user will seldomly want to really get the output "Optional(something)", but is almost always expecting just "something". I believe this should be addressed by a warning to force the user to check the expression to prevent unwanted results. If you indeed want the output of an optional, it's almost always better to use the ?? operator and supply a null value placeholder, e.g. "\(myOptional ?? "<<none>>")", or use myOptional.debugDescription - which is a valid expression that will always return a non-optional value to force the current behavior.<br>
>><br>
>> Krystof<br>
>><br>
>> _______________________________________________<br>
>> swift-evolution mailing list<br>
>> <a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
>> <a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
><br>
> _______________________________________________<br>
> swift-evolution mailing list<br>
> <a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
> <a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</blockquote></div><div dir="ltr">-- <br></div><div><div dir="ltr"><div><div>Dan Appel<br></div></div></div></div>