Skip to content

Instantly share code, notes, and snippets.

@ham-burger
Created July 30, 2020 03:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ham-burger/c7391dab67b46144ac39ea98592e6d44 to your computer and use it in GitHub Desktop.
Save ham-burger/c7391dab67b46144ac39ea98592e6d44 to your computer and use it in GitHub Desktop.
JSON encode decode extension in swift
extension JSONDecoder{
static var commonSettingInstance: JSONDecoder {
let decoder = JSONDecoder()
decoder.keyDecodingStrategy = .convertFromSnakeCase
decoder.dateDecodingStrategy = .iso8601
return decoder
}
}
extension JSONEncoder {
static var commonSettingInstance: JSONEncoder {
let encoder = JSONEncoder()
encoder.keyEncodingStrategy = .convertToSnakeCase
encoder.dateEncodingStrategy = .iso8601
return encoder
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment