Guest User

Untitled

a guest
Nov 17th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. public struct Customer: Decodable {
  2. let name: String
  3. let accountNumber: Int
  4. let archived: Bool
  5.  
  6. private enum CodingKeys: String, CodingKey {
  7. case name
  8. case accountNumber
  9. case archived
  10. }
  11.  
  12. public init(from decoder: Decoder) throws {
  13. let container = try decoder.container(keyedBy: CodingKeys.self)
  14.  
  15. name = try container.decode(String.self, forKey: .name)
  16. accountNumber = try container.unwrapAndDecode(Int.self, forKey: .accountNumber)
  17. archived = try container.unwrapAndDecode(Bool.self, forKey: .archived)
  18. }
  19. }
Add Comment
Please, Sign In to add comment