Oops remove the duplicate &quot;@&quot; in my example.<br><div class="gmail_quote"><div dir="ltr">On Tue, Jul 5, 2016 at 7:27 AM Shawn Erickson &lt;<a href="mailto:shawnce@gmail.com">shawnce@gmail.com</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I would suggest something like the following (yeah I would URLComponents for this but this is just an example)... basically a short hand of some type for (a != nil ? a : b) to deal with optional in string construction.<br><br>&quot;http://\(self.username + &quot;@&quot; : &quot;default&quot;)@<a href="http://my.host.com/pictures/%5C(self.pictureId" target="_blank">my.host.com/pictures/\(self.pictureId</a> : &quot;&quot;)<br><div class="gmail_quote"><div dir="ltr">On Tue, Jul 5, 2016 at 7:14 AM James Campbell via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:rgb(0,0,0)">What would be a better alternative is the ability to have a String Format Token that would unwrap a value, like so</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:rgb(0,0,0)"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:rgb(0,0,0)">let string = String(format: &quot;http://%?/&quot;, url) </div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:rgb(0,0,0)"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:rgb(0,0,0)">None is unwrapped to &quot;http:///&quot;</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:rgb(0,0,0)">Some is unwrapped to &quot;<a href="http://myurl.com/" target="_blank">http://myurl.com/</a>&quot;</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:rgb(0,0,0)"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:rgb(0,0,0)">I think this would be a good trade off rather than having to do an awkward guard dance, make your code unsafe with force-unwraps or end-up with &quot;Optional()&quot; in your string.</div></div><div class="gmail_extra"><br clear="all"><div><div data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr">







<p><b><font color="#cc0000">___________________________________</font></b></p><p><b>James⎥Head of Trolls</b></p><p><b><font color="#cc0000"><a href="mailto:james@supmenow.com" target="_blank">james@supmenow.com</a>⎥<a href="http://supmenow.com" target="_blank">supmenow.com</a></font></b></p><p><b><font size="2">Sup</font></b></p><p><b><font size="2">Runway East
</font></b></p><p><b><font size="2">10 Finsbury Square</font></b></p><p><b><font size="2">London</font></b></p><p><b><font size="2">
EC2A 1AF </font></b></p></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div><div class="gmail_extra">
<br><div class="gmail_quote">On 4 July 2016 at 16:41, Krystof Vasa via swift-evolution <span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">This is now being tracked as <a href="https://bugs.swift.org/browse/SR-1882" target="_blank">https://bugs.swift.org/browse/SR-1882</a> - Chris (Lattner) thought this should not go through the official proposal process as something more complicated, but just add a warning with redundant parentheses around it silencing the warning (<a href="http://article.gmane.org/gmane.comp.lang.swift.evolution/20960" target="_blank">http://article.gmane.org/gmane.comp.lang.swift.evolution/20960</a>).<div><br></div><div><div>The latest version of the proposal (that&#39;s not going to happen) can be found here - <a href="https://gist.github.com/charlieMonroe/82e1519dd2b57029f69bc7abe99d7385" target="_blank">https://gist.github.com/charlieMonroe/82e1519dd2b57029f69bc7abe99d7385</a> - and I&#39;ve implemented it for my own use here:</div></div><div><br></div><div><a href="https://github.com/charlieMonroe/XUCore/blob/master/XUCore/additions/OptionalAdditions.swift" target="_blank">https://github.com/charlieMonroe/XUCore/blob/master/XUCore/additions/OptionalAdditions.swift</a></div><div><br></div><div>I find it better readable than using ?? or extra parentheses around the Optional...<br><div><br><div><blockquote type="cite"><div><div><div>On Jul 4, 2016, at 5:31 PM, David Beck via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:</div><br></div></div><div><div><div><div style="word-wrap:break-word">
&gt; The string interpolation is one of the strong sides of Swift, but also one of its weaknesses.<br>&gt; <br>&gt; It has happened to me more than once that I&#39;ve used the interpolation with an optional by mistake and the result is then far from the expected result.<br>&gt; <br>&gt; This happened mostly before Swift 2.0&#39;s guard expression, but has happened since as well.<br>&gt; <br>&gt; The user will seldomly want to really get the output &quot;Optional(something)&quot;, but is almost always expecting just &quot;something&quot;. 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&#39;s almost always better to use the ?? operator and supply a null value placeholder, e.g. &quot;\(myOptional ?? &quot;&lt;&lt;none&gt;&gt;&quot;)&quot;, or use myOptional.debugDescription - which is a valid expression that will always return a non-optional value to force the current behavior.<br>&gt; <br>&gt; Krystof<br>&gt; <br>&gt; <br>&gt;<span> </span>

<br><br>I really hope a proposal that solves this problem gets through, but I’m not sure blocking optionals specifically is the way to go. In particular there are other types that don’t have a clean string representation. I think that by default string interpolation (meaning String creation specifically) should only accept ValuePreservingStringConvertible types and produce an error for everything else.<div><br></div><div>But, in addition, we need a way to quickly print out values for debugging. I think a new string type (DebugString for example) would be useful for this. print and similar functions could take that as an argument and any type could be interpolated in it’s argument. Further, if you simply say `let a = “\(something)”` and something isn’t ValuePreservingStringConvertible, the type of a should then be DebugString. Converting to string should be strait forward, but require a small step to make it obvious that you are using a string that could have weird characters.<br><div>
<div style="letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><span style="border-collapse:separate;line-height:normal;border-spacing:0px"><div><br><b style="font-size:18px">David Beck</b></div><div style="font-weight:normal"><a href="http://davidbeck.co/" target="_blank">http://davidbeck.co</a></div><div style="font-weight:normal"><a href="http://twitter.com/davbeck" target="_blank">http://twitter.com/davbeck</a></div><div style="font-weight:normal"><a href="http://facebook.com/davbeck" target="_blank">http://facebook.com/davbeck</a></div></span></div>
</div>

<br></div></div></div></div><span>_______________________________________________<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" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></span></div></blockquote></div><br></div></div></div><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></blockquote></div><br></div>
_______________________________________________<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></blockquote></div>