Skip to content

Instantly share code, notes, and snippets.

@josuesilva-hotmart
Created July 28, 2019 21:59
Show Gist options
  • Select an option

  • Save josuesilva-hotmart/f5a3c03b0ddf7d3cb0a7bf3315e994d3 to your computer and use it in GitHub Desktop.

Select an option

Save josuesilva-hotmart/f5a3c03b0ddf7d3cb0a7bf3315e994d3 to your computer and use it in GitHub Desktop.

Revisions

  1. @madcato madcato renamed this gist Mar 21, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Codable+Any.swift → Decodable+Any.swift
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    extension Codable {
    extension Decodable {
    init(_ any: Any) throws {
    let data = try JSONSerialization.data(withJSONObject: any, options: .prettyPrinted)
    let decoder = JSONDecoder()
  2. @madcato madcato created this gist Mar 21, 2018.
    10 changes: 10 additions & 0 deletions Codable+Any.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    extension Codable {
    init(_ any: Any) throws {
    let data = try JSONSerialization.data(withJSONObject: any, options: .prettyPrinted)
    let decoder = JSONDecoder()
    let dateFormatter = DateFormatter()
    dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:sszzz"
    decoder.dateDecodingStrategy = .formatted(dateFormatter)
    self = try decoder.decode(Self.self, from: data)
    }
    }