Skip to content

Instantly share code, notes, and snippets.

@rahulgautam
Forked from eMdOS/Codable.swift
Created February 14, 2018 09:25
Show Gist options
  • Save rahulgautam/0aa480a0493f3b991c4220dc1c56706a to your computer and use it in GitHub Desktop.
Save rahulgautam/0aa480a0493f3b991c4220dc1c56706a to your computer and use it in GitHub Desktop.
Codable {Apple Swift version 4.0 (swiftlang-900.0.45.6 clang-900.0.26)}
extension Encodable {
func encode(with encoder: JSONEncoder = JSONEncoder()) throws -> Data {
return try encoder.encode(self)
}
}
extension Decodable {
static func decode(with decoder: JSONDecoder = JSONDecoder(), from data: Data) throws -> Self {
return try decoder.decode(Self.self, from: data)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment