Last active
November 8, 2017 10:51
-
-
Save gonzo-oin/ad4afdfa37ce65991ace74dadba45944 to your computer and use it in GitHub Desktop.
Swift Duplicatable protocol: Duplicate class object that implement Codable.
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 Duplicatable {} | |
extension Duplicatable where Self: Codable { | |
func duplicate() throws -> Self { | |
return try JSONDecoder().decode(Self.self, from: JSONEncoder().encode(self)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment