Created
June 10, 2017 11:22
-
-
Save anonymous/74d2723e18444344f3635d403e8bf6b8 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
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