Skip to content

Instantly share code, notes, and snippets.

Created June 10, 2017 11:22
Show Gist options
  • Save anonymous/74d2723e18444344f3635d403e8bf6b8 to your computer and use it in GitHub Desktop.
Save anonymous/74d2723e18444344f3635d403e8bf6b8 to your computer and use it in GitHub Desktop.
struct Article: Codable {
let tags: [Tag]
let title: String
enum CodingKeys: CodingKey
{
case k_tag
case k_title
}
init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
tags = try container.decode ([Tag].self, forKey: .k_tag)
title = try container.decode (String.self, forKey: .k_title)
}
func encode(to encoder: Encoder) throws
{
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode (tags, forKey: .k_tag)
try container.encode (title, forKey: .k_title)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment