<div dir="ltr"><div class="gmail_default" style="font-family:georgia,serif">It can't be done by ?? as stringFromDate(Date) returns String instead of String?</div><div class="gmail_default" style="font-family:georgia,serif"><br></div><div class="gmail_default" style="font-family:georgia,serif">Zhaoxin</div><div class="gmail_default" style="font-family:georgia,serif"><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Aug 5, 2016 at 1:42 AM, Jeff Kelley via swift-users <span dir="ltr"><<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>></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">That’s where I would use the ?? operator:<div><br></div><div><font face="Menlo">let dobString = serverDateFormatter.<wbr>stringFromDate(dob) ?? ""</font></div><div><br><div><br></div><div>
<div style="color:rgb(0,0,0);letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><div style="color:rgb(0,0,0);font-family:Helvetica;font-style:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><div style="color:rgb(0,0,0);font-family:Helvetica;font-style:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><div style="color:rgb(0,0,0);font-family:Helvetica;font-style:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><div style="color:rgb(0,0,0);font-family:Helvetica;font-style:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><span style="border-collapse:separate;color:rgb(0,0,0);font-family:Helvetica;font-style:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;border-spacing:0px"><div style="word-wrap:break-word"><div>Jeff Kelley</div><div><br></div><div><a href="mailto:SlaunchaMan@gmail.com" target="_blank">SlaunchaMan@gmail.com</a> | <a href="https://twitter.com/SlaunchaMan" target="_blank">@<wbr>SlaunchaMan</a> | <a href="http://jeffkelley.org" target="_blank">jeffkelley.org</a></div></div></span></div></div></div></div></div>
</div>
<br><div><blockquote type="cite"><div><div class="h5"><div>On Aug 4, 2016, at 1:32 PM, Daniel Tartaglia via swift-users <<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>> wrote:</div><br></div></div><div><div><div class="h5"><div style="word-wrap:break-word"><font face="Menlo">Currently I do stuff like this:</font><div><br></div><div><div style="margin:0px;line-height:normal;font-family:Menlo"><div style="margin:0px;line-height:normal"><span style="color:#bb2ca2">let</span><span> dobString: </span><span style="color:#703daa">String</span></div><div style="margin:0px;line-height:normal"><span style="color:#bb2ca2">if</span><span> </span><span style="color:#bb2ca2">let</span><span> dob = dob {</span></div><div style="margin:0px;line-height:normal"><span><span style="white-space:pre-wrap">        </span>dobString = </span><span style="color:#4f8187">serverDateFormatter</span><span>.</span><span style="color:#3d1d81">stringFrom<wbr>Date</span><span>(dob)</span></div><div style="margin:0px;line-height:normal"><span>}</span></div><div style="margin:0px;line-height:normal;color:rgb(187,44,162)"><span>else</span><span> {</span></div><div style="margin:0px;line-height:normal"><span><span style="white-space:pre-wrap">        </span>dobString = </span><span style="color:#d12f1b">""</span></div><div style="margin:0px;line-height:normal"><span>}</span></div><div><span><br></span></div><div><span>Is there a better, more idiomatic, way to do this sort of thing?</span></div><div><span><br></span></div></div></div></div></div></div>______________________________<wbr>_________________<br>swift-users mailing list<br><a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-users" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-users</a><br></div></blockquote></div><br></div></div><br>______________________________<wbr>_________________<br>
swift-users mailing list<br>
<a href="mailto:swift-users@swift.org">swift-users@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-users" rel="noreferrer" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-users</a><br>
<br></blockquote></div><br></div>