[swift-evolution] Proposal: Deprecate optionals in string interpolation

Charlie Monroe charlie at charliemonroe.net
Fri Jun 17 00:41:00 CDT 2016


> On Jun 17, 2016, at 1:12 AM, Brent Royal-Gordon <brent at architechies.com> wrote:
> 
>> 	- func descriptionWithDefaultValue(_ defaultValue: String = "nil") -> String - which would return either the description of the value, or `defaultValue`.
> 
> This is the same as myOptional?.description ?? defaultValue, isn't it? So do we need it?

We need it because:

- myOptional doesn't necessarily need to contain a CustomStringConvertible, hence .description might not be defined on it (enums, structs, pure Swift classes, ...).

- I have originally suggested making Optional CustomStringConvertible so that .description would return the same value as descriptionWithDefaultValue() (and hence just myOptional.description would be sufficient) and .debugDescription would keep its current behavior. But it was pointed out to me that invoking debugDescription and description is explicitly discouraged from in the documentation and that it's not a correct solution.

See updated proposal on 

https://gist.github.com/charlieMonroe/82e1519dd2b57029f69bc7abe99d7385

> 
> -- 
> Brent Royal-Gordon
> Architechies
> 



More information about the swift-evolution mailing list