Skip to content

Instantly share code, notes, and snippets.

@iwill
Last active August 17, 2021 01:27
Show Gist options
  • Save iwill/fd14a420b0d116004df5ff9189f29b7e to your computer and use it in GitHub Desktop.
Save iwill/fd14a420b0d116004df5ff9189f29b7e to your computer and use it in GitHub Desktop.
Code Snippet: Adopte to ExCodable protocol
<#extension/struct/class#> <#Type#>: ExCodable {
static let <#keyMapping#>: [KeyMap<<#SelfType#>>] = [
KeyMap(\.<#property#>, to: <#"key"#>),
<#...#>
]
init(from decoder: Decoder) throws {
try decode<#Reference#>(from: decoder, with: Self.<#keyMapping#>)
}
func encode(to encoder: Encoder) throws {
try encode(to: encoder, with: Self.<#keyMapping#>)
}
}
@iwill
Copy link
Author

iwill commented Feb 21, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment