Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extension Decodable {
- // Converts a dictionary to the desired type
- static func decode(dictionary: [String: Any]) throws -> Self {
- let data = try JSONSerialization.data(withJSONObject: dictionary, options: [])
- return (try JSONDecoder().decode(Self.self, from: data))
- }
- }
- extension Encodable {
- // Turns your object into Data
- func encode() throws -> Data {
- return try JSONEncoder().encode(self)
- }
- }
Add Comment
Please, Sign In to add comment