From bc4f9835a5ca5d21ea3eb4893dd9c7c948cca5a5 Mon Sep 17 00:00:00 2001 From: Madhas Date: Sat, 12 May 2018 14:44:45 +0300 Subject: [PATCH] update Post model --- Tests/Models/Post.swift | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/Tests/Models/Post.swift b/Tests/Models/Post.swift index ab6a170d..dfb71c3b 100644 --- a/Tests/Models/Post.swift +++ b/Tests/Models/Post.swift @@ -22,19 +22,23 @@ import ObjectMapper -struct Post: ImmutableMappable { +struct Post: Decodable { + + enum CodingKeys: String, CodingKey { + case userId + case postId = "id" + case title + case body + } let userId: Int let postId: Int let title: String let body: String - init(userId: Int, postId: Int, title: String, body: String) { - self.userId = userId - self.postId = postId - self.title = title - self.body = body - } +} + +extension Post: ImmutableMappable { init(map: Map) throws { userId = try map.value("userId") @@ -42,14 +46,13 @@ struct Post: ImmutableMappable { title = try map.value("title") body = try map.value("body") } - + mutating func mapping(map: Map) { userId >>> map["userId"] postId >>> map["id"] title >>> map["title"] body >>> map["body"] } - } extension Post: Equatable {