Created
March 13, 2019 08:06
-
-
Save hellensoloviy/9cceacd15cfe165151be62a92d3485d6 to your computer and use it in GitHub Desktop.
JSONDecodable
This file contains hidden or 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
import Foundation | |
protocol JSONDecodable { | |
func jsonParams() throws -> [String : Any] | |
} | |
extension JSONDecodable where Self : Codable { | |
func jsonParams() throws -> [String : Any] { | |
let encoder = JSONEncoder() | |
let data = try encoder.encode(self) | |
return try JSONSerialization.jsonObject(with: data, options: []) as! [String: Any] //force unwrap | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment