Oh, wait, I can’t read. Ignore that; then there’s no easy way to do it.

Saagar Jha



> On Aug 4, 2016, at 12:42, Saagar Jha <[email protected]> wrote:
> 
> Ahh…then optional chaining is the way to go: `let dobString = 
> serverDateFormatter?.stringFromDate(dob) ?? ""`
> 
> Saagar Jha
> 
> 
> 
>> On Aug 4, 2016, at 12:41, Daniel Tartaglia <[email protected] 
>> <mailto:[email protected]>> wrote:
>> 
>> That’s not possible. stringFromDate requires an NSDate, but dob is an 
>> optional<NSDate>
>> 
>>> On Aug 4, 2016, at 2:59 PM, Saagar Jha <[email protected] 
>>> <mailto:[email protected]>> wrote:
>>> 
>>> As such, there shouldn’t be a need for an if; `let dobString = 
>>> serverDateFormatter.stringFromDate(dob)` should be sufficient.
>>> 
>>> Saagar Jha
>>> 
>>> 
>>> 
>>>> On Aug 4, 2016, at 11:55, Zhao Xin via swift-users <[email protected] 
>>>> <mailto:[email protected]>> wrote:
>>>> 
>>>> It can't be done by ?? as stringFromDate(Date) returns String instead of 
>>>> String?
>>>> 
>>>> Zhaoxin
>>>> 
>>>> 
>>>> On Fri, Aug 5, 2016 at 1:42 AM, Jeff Kelley via swift-users 
>>>> <[email protected] <mailto:[email protected]>> wrote:
>>>> That’s where I would use the ?? operator:
>>>> 
>>>> let dobString = serverDateFormatter.stringFromDate(dob) ?? ""
>>>> 
>>>> 
>>>> Jeff Kelley
>>>> 
>>>> [email protected] <mailto:[email protected]> | @SlaunchaMan 
>>>> <https://twitter.com/SlaunchaMan> | jeffkelley.org <http://jeffkelley.org/>
>>>>> On Aug 4, 2016, at 1:32 PM, Daniel Tartaglia via swift-users 
>>>>> <[email protected] <mailto:[email protected]>> wrote:
>>>>> 
>>>>> Currently I do stuff like this:
>>>>> 
>>>>> let dobString: String
>>>>> if let dob = dob {
>>>>>   dobString = serverDateFormatter.stringFromDate(dob)
>>>>> }
>>>>> else {
>>>>>   dobString = ""
>>>>> }
>>>>> 
>>>>> Is there a better, more idiomatic, way to do this sort of thing?
>>>>> 
>>>>> _______________________________________________
>>>>> swift-users mailing list
>>>>> [email protected] <mailto:[email protected]>
>>>>> https://lists.swift.org/mailman/listinfo/swift-users 
>>>>> <https://lists.swift.org/mailman/listinfo/swift-users>
>>>> 
>>>> 
>>>> _______________________________________________
>>>> swift-users mailing list
>>>> [email protected] <mailto:[email protected]>
>>>> https://lists.swift.org/mailman/listinfo/swift-users 
>>>> <https://lists.swift.org/mailman/listinfo/swift-users>
>>>> 
>>>> 
>>>> _______________________________________________
>>>> swift-users mailing list
>>>> [email protected] <mailto:[email protected]>
>>>> https://lists.swift.org/mailman/listinfo/swift-users 
>>>> <https://lists.swift.org/mailman/listinfo/swift-users>
>>> 
>> 
> 

_______________________________________________
swift-users mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-users

Reply via email to