Showing
1 changed file
with
25 additions
and
23 deletions
| ... | @@ -42,6 +42,31 @@ public class MerchantCategoryModel: NSObject { | ... | @@ -42,6 +42,31 @@ public class MerchantCategoryModel: NSObject { |
| 42 | self.name = dictionary["name"] as? String | 42 | self.name = dictionary["name"] as? String |
| 43 | } | 43 | } |
| 44 | 44 | ||
| 45 | + // MARK: - Codable Support | ||
| 46 | + | ||
| 47 | + private enum CodingKeys: String, CodingKey { | ||
| 48 | + case uuid | ||
| 49 | + case admin_name | ||
| 50 | + case image | ||
| 51 | + case parent | ||
| 52 | + case fields | ||
| 53 | + case children | ||
| 54 | + case count | ||
| 55 | + case name | ||
| 56 | + } | ||
| 57 | + | ||
| 58 | + public required init(from decoder: Decoder) throws { | ||
| 59 | + let container = try decoder.container(keyedBy: CodingKeys.self) | ||
| 60 | + self.uuid = try container.decodeIfPresent(String.self, forKey: .uuid) | ||
| 61 | + self.admin_name = try container.decodeIfPresent(String.self, forKey: .admin_name) | ||
| 62 | + self.image = try container.decodeIfPresent(String.self, forKey: .image) | ||
| 63 | + self.parent = try container.decodeIfPresent(String.self, forKey: .parent) | ||
| 64 | + self.fields = try container.decodeIfPresent(String.self, forKey: .fields) | ||
| 65 | + self.count = try container.decodeIfPresent(Int.self, forKey: .count) | ||
| 66 | + self.name = try container.decodeIfPresent(String.self, forKey: .name) | ||
| 67 | + self.children = [] // Default empty array for children | ||
| 68 | + } | ||
| 69 | + | ||
| 45 | // MARK: - Public Accessors | 70 | // MARK: - Public Accessors |
| 46 | 71 | ||
| 47 | public var _uuid: String { | 72 | public var _uuid: String { |
| ... | @@ -110,17 +135,6 @@ public class MerchantCategoryModel: NSObject { | ... | @@ -110,17 +135,6 @@ public class MerchantCategoryModel: NSObject { |
| 110 | // MARK: - Codable Support | 135 | // MARK: - Codable Support |
| 111 | 136 | ||
| 112 | extension MerchantCategoryModel: Codable { | 137 | extension MerchantCategoryModel: Codable { |
| 113 | - private enum CodingKeys: String, CodingKey { | ||
| 114 | - case uuid | ||
| 115 | - case admin_name | ||
| 116 | - case image | ||
| 117 | - case parent | ||
| 118 | - case fields | ||
| 119 | - case children | ||
| 120 | - case count | ||
| 121 | - case name | ||
| 122 | - } | ||
| 123 | - | ||
| 124 | public func encode(to encoder: Encoder) throws { | 138 | public func encode(to encoder: Encoder) throws { |
| 125 | var container = encoder.container(keyedBy: CodingKeys.self) | 139 | var container = encoder.container(keyedBy: CodingKeys.self) |
| 126 | try container.encode(uuid, forKey: .uuid) | 140 | try container.encode(uuid, forKey: .uuid) |
| ... | @@ -132,18 +146,6 @@ extension MerchantCategoryModel: Codable { | ... | @@ -132,18 +146,6 @@ extension MerchantCategoryModel: Codable { |
| 132 | try container.encodeIfPresent(name, forKey: .name) | 146 | try container.encodeIfPresent(name, forKey: .name) |
| 133 | // Note: children is [Any] so we skip encoding it for now | 147 | // Note: children is [Any] so we skip encoding it for now |
| 134 | } | 148 | } |
| 135 | - | ||
| 136 | - public required init(from decoder: Decoder) throws { | ||
| 137 | - let container = try decoder.container(keyedBy: CodingKeys.self) | ||
| 138 | - self.uuid = try container.decodeIfPresent(String.self, forKey: .uuid) | ||
| 139 | - self.admin_name = try container.decodeIfPresent(String.self, forKey: .admin_name) | ||
| 140 | - self.image = try container.decodeIfPresent(String.self, forKey: .image) | ||
| 141 | - self.parent = try container.decodeIfPresent(String.self, forKey: .parent) | ||
| 142 | - self.fields = try container.decodeIfPresent(String.self, forKey: .fields) | ||
| 143 | - self.count = try container.decodeIfPresent(Int.self, forKey: .count) | ||
| 144 | - self.name = try container.decodeIfPresent(String.self, forKey: .name) | ||
| 145 | - self.children = [] // Default empty array for children | ||
| 146 | - } | ||
| 147 | } | 149 | } |
| 148 | 150 | ||
| 149 | // MARK: - Debug Description | 151 | // MARK: - Debug Description | ... | ... |
-
Please register or login to post a comment