Skip to content

Instantly share code, notes, and snippets.

@geek1706
Created August 23, 2018 07:09
Show Gist options
  • Save geek1706/5fb446c0404e948d479a34d31e6986e3 to your computer and use it in GitHub Desktop.
Save geek1706/5fb446c0404e948d479a34d31e6986e3 to your computer and use it in GitHub Desktop.
import ObjectMapper
class CustomDateTransform: TransformType {
static let dateFormatter: DateFormatter = {
let df = DateFormatter()
df.dateFormat = "yyyy-MM-dd"
return df
}()
func transformFromJSON(_ value: Any?) -> Date? {
if let dateStr = value as? String {
return BirthdayDateTransform.dateFormatter.date(from: dateStr)
}
return nil
}
func transformToJSON(_ value: Date?) -> String? {
return nil
}
typealias Object = Date
typealias JSON = String
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment