Skip to content

Instantly share code, notes, and snippets.

@almatri
Last active July 19, 2017 09:21
Show Gist options
  • Save almatri/5d5e05a2c8b04e826a55b7dfb1414562 to your computer and use it in GitHub Desktop.
Save almatri/5d5e05a2c8b04e826a55b7dfb1414562 to your computer and use it in GitHub Desktop.
Swift DateFormatter Singleton
import UIKit
class Dater: DateFormatter {
static var shared = Dater()
private override init() {
super.init()
self.locale = NSLocale(localeIdentifier: "en_US") as Locale!
}
func date(from string: String, format: String) -> Date? {
self.dateFormat = format
return date(from: string)
}
func string(from date: Date, format: String) -> String? {
self.dateFormat = format
return string(from: date)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment