I have an extension set up on String
to return the current date in the same format so that anywhere in code it can be called and the same format is used, allowing for consistency. My code is
extension String {
static let dateString = DateFormatter.localizedString(from: Date(), dateStyle: .short, timeStyle: .short)
}
The only problem is that when I call it the same exact time is returned until the app is killed. If I'm using Date()
then it should be using a fresh value every time, right? Why is this not the case?