Skip to content

Instantly share code, notes, and snippets.

@foxicode
Created July 29, 2023 13:05
Show Gist options
  • Select an option

  • Save foxicode/0a9c8c5cfe2efe0919e20e78161c8562 to your computer and use it in GitHub Desktop.

Select an option

Save foxicode/0a9c8c5cfe2efe0919e20e78161c8562 to your computer and use it in GitHub Desktop.
Encodable copyCodable Swift extension
public extension Encodable where Self: Decodable {
func copyCodable() throws -> Self {
let data = try JSONEncoder().encode(self)
return try JSONDecoder().decode(Self.self, from: data)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment