Last active
November 17, 2017 07:54
-
-
Save shiningabdul/914597eef39506d5a07e61136c2be835 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
import Foundation | |
protocol Transmittable : Codable { | |
} | |
extension Transmittable { | |
func encode() -> Data { | |
var data:Data = Data() | |
try? data = JSONEncoder().encode(self) | |
return data | |
} | |
static func decode(from data:Data?) -> Self? { | |
guard let data = data else { | |
return nil | |
} | |
let decoder = JSONDecoder() | |
let response = try? decoder.decode(self, from: data) | |
return response | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment