This doesn’t work because `dob` is optional and `stringFromDate` only takes a non-optional date.
> 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: > > > > 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](mailto:[email protected]) > > https://lists.swift.org/mailman/listinfo/swift-users > > > _______________________________________________ swift-users mailing list [email protected] https://lists.swift.org/mailman/listinfo/swift-users
