mirror of
https://github.com/valitydev/openapi-generator.git
synced 2024-11-06 18:45:23 +00:00
[Swift4] Allow for custom dateformatter to be used (#6672)
* Add a custom dateformat to be set * Samples updated * Update CodableHelper.swift Change to correct format: decoder.dataDecodingStrategy = .base64 * Update CodableHelper.mustache Add `decoder.dataDecodingStrategy = .base64` back * Update CodableHelper.swift Fix `decoder.dataDecodingStrategy = .base64` * Update CodableHelper.swift Fix `decoder.dataDecodingStrategy = .base64`
This commit is contained in:
parent
b3133a2d74
commit
5af788cb9f
@ -11,14 +11,20 @@ public typealias EncodeResult = (data: Data?, error: Error?)
|
||||
|
||||
open class CodableHelper {
|
||||
|
||||
open static var dateformatter: DateFormatter?
|
||||
|
||||
open class func decode<T>(_ type: T.Type, from data: Data) -> (decodableObj: T?, error: Error?) where T : Decodable {
|
||||
var returnedDecodable: T? = nil
|
||||
var returnedError: Error? = nil
|
||||
|
||||
let decoder = JSONDecoder()
|
||||
decoder.dataDecodingStrategy = .base64
|
||||
if #available(iOS 10.0, *) {
|
||||
decoder.dateDecodingStrategy = .iso8601
|
||||
if let df = self.dateformatter {
|
||||
decoder.dateDecodingStrategy = .formatted(df)
|
||||
} else {
|
||||
decoder.dataDecodingStrategy = .base64
|
||||
if #available(iOS 10.0, *) {
|
||||
decoder.dateDecodingStrategy = .iso8601
|
||||
}
|
||||
}
|
||||
|
||||
do {
|
||||
|
@ -11,14 +11,20 @@ public typealias EncodeResult = (data: Data?, error: Error?)
|
||||
|
||||
open class CodableHelper {
|
||||
|
||||
open static var dateformatter: DateFormatter?
|
||||
|
||||
open class func decode<T>(_ type: T.Type, from data: Data) -> (decodableObj: T?, error: Error?) where T : Decodable {
|
||||
var returnedDecodable: T? = nil
|
||||
var returnedError: Error? = nil
|
||||
|
||||
let decoder = JSONDecoder()
|
||||
decoder.dataDecodingStrategy = .base64
|
||||
if #available(iOS 10.0, *) {
|
||||
decoder.dateDecodingStrategy = .iso8601
|
||||
if let df = self.dateformatter {
|
||||
decoder.dateDecodingStrategy = .formatted(df)
|
||||
} else {
|
||||
decoder.dataDecodingStrategy = .base64
|
||||
if #available(iOS 10.0, *) {
|
||||
decoder.dateDecodingStrategy = .iso8601
|
||||
}
|
||||
}
|
||||
|
||||
do {
|
||||
|
@ -11,14 +11,20 @@ public typealias EncodeResult = (data: Data?, error: Error?)
|
||||
|
||||
open class CodableHelper {
|
||||
|
||||
open static var dateformatter: DateFormatter?
|
||||
|
||||
open class func decode<T>(_ type: T.Type, from data: Data) -> (decodableObj: T?, error: Error?) where T : Decodable {
|
||||
var returnedDecodable: T? = nil
|
||||
var returnedError: Error? = nil
|
||||
|
||||
let decoder = JSONDecoder()
|
||||
decoder.dataDecodingStrategy = .base64
|
||||
if #available(iOS 10.0, *) {
|
||||
decoder.dateDecodingStrategy = .iso8601
|
||||
if let df = self.dateformatter {
|
||||
decoder.dateDecodingStrategy = .formatted(df)
|
||||
} else {
|
||||
decoder.dataDecodingStrategy = .base64
|
||||
if #available(iOS 10.0, *) {
|
||||
decoder.dateDecodingStrategy = .iso8601
|
||||
}
|
||||
}
|
||||
|
||||
do {
|
||||
|
@ -11,14 +11,20 @@ public typealias EncodeResult = (data: Data?, error: Error?)
|
||||
|
||||
open class CodableHelper {
|
||||
|
||||
open static var dateformatter: DateFormatter?
|
||||
|
||||
open class func decode<T>(_ type: T.Type, from data: Data) -> (decodableObj: T?, error: Error?) where T : Decodable {
|
||||
var returnedDecodable: T? = nil
|
||||
var returnedError: Error? = nil
|
||||
|
||||
let decoder = JSONDecoder()
|
||||
decoder.dataDecodingStrategy = .base64
|
||||
if #available(iOS 10.0, *) {
|
||||
decoder.dateDecodingStrategy = .iso8601
|
||||
if let df = self.dateformatter {
|
||||
decoder.dateDecodingStrategy = .formatted(df)
|
||||
} else {
|
||||
decoder.dataDecodingStrategy = .base64
|
||||
if #available(iOS 10.0, *) {
|
||||
decoder.dateDecodingStrategy = .iso8601
|
||||
}
|
||||
}
|
||||
|
||||
do {
|
||||
|
Loading…
Reference in New Issue
Block a user