<div dir="ltr"><div class="gmail_default" style="font-family:georgia,serif">Thank you. I think this is the best I saw today.</div><div class="gmail_default" style="font-family:georgia,serif"><br></div><div class="gmail_default" style="font-family:georgia,serif">Zhaoxin</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Aug 5, 2016 at 5:24 AM, Erica Sadun via swift-users <span dir="ltr">&lt;<a href="mailto:swift-users@swift.org" target="_blank">swift-users@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"><div>And Greg from Omni Group has an even better solution for you.  Since DateFormatter inherits from Formatter, you can use its `string(for:)` which accepts optionals:</div><div><br></div><div><div style="margin:0px;font-size:16px;line-height:normal;font-family:Menlo"><span style="color:#bb2ca2">let</span><span> dobString3 = </span><span style="color:#4f8187">serverDateFormatter</span><span>.</span><span style="color:#3d1d81">string</span><span>(<wbr>for:</span><span style="color:#4f8187">dob</span><span>) ?? </span><span style="color:#d12f1b">&quot;&quot;</span></div></div><div><span style="color:#d12f1b"><br></span></div>-- E<div><div class="h5"><div><br><div><blockquote type="cite"><div>On Aug 4, 2016, at 3:17 PM, Erica Sadun via swift-users &lt;<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>&gt; wrote:</div><br><div><div style="font-family:Palatino-Roman;font-size:14px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><blockquote type="cite"><div><br>On Aug 4, 2016, at 1:41 PM, Tim Vermeulen via swift-users &lt;<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>&gt; wrote:</div><br><div><div>You want `flatMap`:<br><br>let dobString = dob.flatMap(<wbr>serverDateFormatter.<wbr>stringFromDate)<br><br>Or if you want `dobString` to be non-optional:<br><br>let dobString = dob.flatMap(<wbr>serverDateFormatter.<wbr>stringFromDate) ?? “&quot;<br></div></div></blockquote><div><br></div>You can just use map here too, right?</div><div style="font-family:Palatino-Roman;font-size:14px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br></div><div style="font-family:Palatino-Roman;font-size:14px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div style="margin:0px;font-size:16px;line-height:normal;font-family:Menlo"><span style="color:rgb(187,44,162)">let</span><span><span> </span>dobString2:<span> </span></span><span style="color:rgb(112,61,170)">String</span><span><span> </span>=<span> </span></span><span style="color:rgb(79,129,135)">dob</span><span>.</span><span style="color:rgb(61,29,129)">m<wbr>ap</span><span>(</span><span style="color:rgb(79,129,135)">serverDateFormatter</span><span>.</span><span style="color:rgb(61,29,129)">string</span><span>) ??<span> </span></span><span style="color:rgb(209,47,27)">&quot;&quot;</span></div></div><div style="font-family:Palatino-Roman;font-size:14px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br></div><div style="font-family:Palatino-Roman;font-size:14px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">I was a little surprised that this didn&#39;t need the rest of the selector signature but that&#39;s because parameter stripping and type matching, isn&#39;t it?</div><div style="font-family:Palatino-Roman;font-size:14px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br><blockquote type="cite"><div><div><br><blockquote type="cite">Currently I do stuff like this:<br><br>letdobString:String<br>ifletdob = dob {<br>dobString =serverDateFormatter.<wbr>stringFromDate(dob)<br>}<br>else{<br>dobString =&quot;&quot;<br>}<br><br>Is there a better, more idiomatic, way to do this sort of thing?<br><br><br><br><br></blockquote>______________________________<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></div></blockquote></div><br style="font-family:Palatino-Roman;font-size:14px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:Palatino-Roman;font-size:14px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">______________________________<wbr>_________________</span><br style="font-family:Palatino-Roman;font-size:14px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:Palatino-Roman;font-size:14px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">swift-users mailing list</span><br style="font-family:Palatino-Roman;font-size:14px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><a href="mailto:swift-users@swift.org" style="font-family:Palatino-Roman;font-size:14px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" target="_blank">swift-users@swift.org</a><br style="font-family:Palatino-Roman;font-size:14px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><a href="https://lists.swift.org/mailman/listinfo/swift-users" style="font-family:Palatino-Roman;font-size:14px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-users</a></div></blockquote></div><br></div></div></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>