Last active
July 19, 2017 09:21
-
-
Save almatri/5d5e05a2c8b04e826a55b7dfb1414562 to your computer and use it in GitHub Desktop.
Swift DateFormatter Singleton
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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