Last active
June 16, 2020 20:39
-
-
Save furkankaplan/ba40693ba1fe94b8af5aba93ded2c328 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// DictionaryExtension.swift | |
// reserve-ios | |
// | |
// Created by Furkan Kaplan on 16.06.2020. | |
// Copyright © 2020 Furkan Kaplan. All rights reserved. | |
// | |
import Foundation | |
extension Dictionary { | |
func convertTo<T2: Codable>(object class: T2.Type) -> T2? { | |
do { | |
let decoder = JSONDecoder() | |
decoder.dateDecodingStrategy = .iso8601 | |
let jsonData = try JSONSerialization.data(withJSONObject: self, options: [.prettyPrinted]) | |
let item = try decoder.decode(T2.self, from: jsonData) | |
print(item) | |
return item | |
} catch let error { | |
print(error) | |
} | |
return nil | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment