Michael Long
1 min readAug 24, 2020

--

private let df = DateFormatter()extension String {
func toDate() -> Date? {
return df.date(from: self)
}
}
extension Date {
func toString() -> String {
return df.string(from: self)
}
}

Not quite sure how it’s impossible. I’d probably do some locking as this isn’t thread-safe, but otherwise it’s pretty easy to share the formatter.

And I get the assumption, but the problem is that someone is likely to copy the code into a project verbatim, and then someone else is likely to see it pop up in autocomplete and then use it without knowing the built-in limitations.

My personal opinion is that articles on tools should make sure the tools are as robust as possible, but that’s just me. Enjoyed the article.

--

--

Michael Long
Michael Long

Written by Michael Long

I write about Apple, Swift, and SwiftUI in particular, and technology in general. I'm also a Lead iOS Engineer at InRhythm, a modern digital consulting firm.

No responses yet