You want `flatMap`:
let dobString = dob.flatMap(serverDateFormatter.stringFromDate)
Or if you want `dobString` to be non-optional:
let dobString = dob.flatMap(serverDateFormatter.stringFromDate) ?? “"
> Currently I do stuff like this:
>
> letdobString:String
> ifletdob = 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]
https://lists.swift.org/mailman/listinfo/swift-users