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.