Created
October 6, 2018 01:09
-
-
Save lugearma/fbfe6bb2dc87a7765e893b30bf3e4422 to your computer and use it in GitHub Desktop.
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
extension String { | |
func toDate(withFormat format: String = "yyyy-MM-dd") -> Date { | |
let dateFormatter = DateFormatter() | |
dateFormatter.dateFormat = format | |
guard let date = dateFormatter.date(from: self) else { | |
preconditionFailure("Take a look to your format") | |
} | |
return date | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment