<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">As such, there shouldn’t be a need for an if; `let dobString = serverDateFormatter.stringFromDate(dob)` should be sufficient.<br class=""><div class="">
<br class="Apple-interchange-newline"><span style="color: rgb(0, 0, 0); font-family: 'SF UI Text'; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; display: inline !important; float: none;" class="">Saagar Jha</span><br style="color: rgb(0, 0, 0); font-family: 'SF UI Text'; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;" class=""><br style="color: rgb(0, 0, 0); font-family: 'SF UI Text'; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;" class=""><br style="color: rgb(0, 0, 0); font-family: 'SF UI Text'; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;" class="">
</div>
<br class=""><div><blockquote type="cite" class=""><div class="">On Aug 4, 2016, at 11:55, Zhao Xin via swift-users &lt;<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class="gmail_default" style="font-family:georgia,serif">It can't be done by ?? as&nbsp;stringFromDate(Date) returns String instead of String?</div><div class="gmail_default" style="font-family:georgia,serif"><br class=""></div><div class="gmail_default" style="font-family:georgia,serif">Zhaoxin</div><div class="gmail_default" style="font-family:georgia,serif"><br class=""></div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Fri, Aug 5, 2016 at 1:42 AM, Jeff Kelley via swift-users <span dir="ltr" class="">&lt;<a href="mailto:swift-users@swift.org" target="_blank" class="">swift-users@swift.org</a>&gt;</span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class="">That’s where I would use the ?? operator:<div class=""><br class=""></div><div class=""><font face="Menlo" class="">let dobString = serverDateFormatter.<wbr class="">stringFromDate(dob) ?? ""</font></div><div class=""><br class=""><div class=""><br class=""></div><div class="">
<div style="letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; word-wrap: break-word;" class=""><div style="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;" class=""><div style="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;" class=""><div style="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;" class=""><div style="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;" class=""><span style="border-collapse: separate; 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;" class=""><div style="word-wrap:break-word" class=""><div class="">Jeff Kelley</div><div class=""><br class=""></div><div class=""><a href="mailto:SlaunchaMan@gmail.com" target="_blank" class="">SlaunchaMan@gmail.com</a>&nbsp;|&nbsp;<a href="https://twitter.com/SlaunchaMan" target="_blank" class="">@<wbr class="">SlaunchaMan</a>&nbsp;|&nbsp;<a href="http://jeffkelley.org/" target="_blank" class="">jeffkelley.org</a></div></div></span></div></div></div></div></div>
</div>
<br class=""><div class=""><blockquote type="cite" class=""><div class=""><div class="h5"><div class="">On Aug 4, 2016, at 1:32 PM, Daniel Tartaglia via swift-users &lt;<a href="mailto:swift-users@swift.org" target="_blank" class="">swift-users@swift.org</a>&gt; wrote:</div><br class=""></div></div><div class=""><div class=""><div class="h5"><div style="word-wrap:break-word" class=""><font face="Menlo" class="">Currently I do stuff like this:</font><div class=""><br class=""></div><div class=""><div style="margin:0px;line-height:normal;font-family:Menlo" class=""><div style="margin:0px;line-height:normal" class=""><span style="color:#bb2ca2" class="">let</span><span class=""> dobString: </span><span style="color:#703daa" class="">String</span></div><div style="margin:0px;line-height:normal" class=""><span style="color:#bb2ca2" class="">if</span><span class=""> </span><span style="color:#bb2ca2" class="">let</span><span class=""> dob = dob {</span></div><div style="margin:0px;line-height:normal" class=""><span class=""><span style="white-space:pre-wrap" class="">        </span>dobString = </span><span style="color:#4f8187" class="">serverDateFormatter</span><span class="">.</span><span style="color:#3d1d81" class="">stringFrom<wbr class="">Date</span><span class="">(dob)</span></div><div style="margin:0px;line-height:normal" class=""><span class="">}</span></div><div style="margin:0px;line-height:normal;color:rgb(187,44,162)" class=""><span class="">else</span><span class=""> {</span></div><div style="margin:0px;line-height:normal" class=""><span class=""><span style="white-space:pre-wrap" class="">        </span>dobString = </span><span style="color:#d12f1b" class="">""</span></div><div style="margin:0px;line-height:normal" class=""><span class="">}</span></div><div class=""><span class=""><br class=""></span></div><div class=""><span class="">Is there a better, more idiomatic, way to do this sort of thing?</span></div><div class=""><span class=""><br class=""></span></div></div></div></div></div></div>______________________________<wbr class="">_________________<br class="">swift-users mailing list<br class=""><a href="mailto:swift-users@swift.org" target="_blank" class="">swift-users@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-users" target="_blank" class="">https://lists.swift.org/<wbr class="">mailman/listinfo/swift-users</a><br class=""></div></blockquote></div><br class=""></div></div><br class="">______________________________<wbr class="">_________________<br class="">
swift-users mailing list<br class="">
<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a><br class="">
<a href="https://lists.swift.org/mailman/listinfo/swift-users" rel="noreferrer" target="_blank" class="">https://lists.swift.org/<wbr class="">mailman/listinfo/swift-users</a><br class="">
<br class=""></blockquote></div><br class=""></div>
_______________________________________________<br class="">swift-users mailing list<br class=""><a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-users<br class=""></div></blockquote></div><br class=""></body></html>