Say you have a date formatter that is global
let df:DateFormatter = DateFormatter()
Ideally it would be good to do the .dateFormat
setup at the same global initialization time - sort of like this
let df:DateFormatter = DateFormatter().dateFormat = "yyyy-MM-dd"
But there's no alternative initialization for DateFormatter (there's nothing like this DateFormatter(withDateFormat: "yyyy-MM-dd")
)
Really, is there a Swift solution to this? Is there syntax for a code block outside of any class, which, runs early before anything and in which you can setup things of that nature?
(Note - I am entirely aware of alternative approaches such as singletons, extension, etc: this is a Swift structure question, thanks.)