Skip to content

Instantly share code, notes, and snippets.

@lugearma
Created October 6, 2018 01:09
Show Gist options
  • Save lugearma/fbfe6bb2dc87a7765e893b30bf3e4422 to your computer and use it in GitHub Desktop.
Save lugearma/fbfe6bb2dc87a7765e893b30bf3e4422 to your computer and use it in GitHub Desktop.
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