Guest User

Untitled

a guest
May 27th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. extension Decodable {
  2. // Converts a dictionary to the desired type
  3. static func decode(dictionary: [String: Any]) throws -> Self {
  4. let data = try JSONSerialization.data(withJSONObject: dictionary, options: [])
  5. return (try JSONDecoder().decode(Self.self, from: data))
  6. }
  7. }
  8.  
  9. extension Encodable {
  10. // Turns your object into Data
  11. func encode() throws -> Data {
  12. return try JSONEncoder().encode(self)
  13. }
  14. }
Add Comment
Please, Sign In to add comment