Skip to content

Instantly share code, notes, and snippets.

@alexnikol

alexnikol/.swift

Created Aug 17, 2020
Embed
What would you like to do?
Pagination duplicates problem
class Pagination: Decodable {
var pets: [Pet]
var currentPage: Int
var totalPages: Int
enum ResultCodingKeys: String, CodingKey {
case pets, currentPage, totalPages
}
required init(from decoder: Decoder) throws {
let objectsContainer = try decoder.container(keyedBy: ResultCodingKeys.self)
currentPage = try objectsContainer.decode(Int.self, forKey: .currentPage)
totalPages = try objectsContainer.decode(Int.self, forKey: .totalPages)
pets = try objectsContainer.decode([Pet].self, forKey: .pets)
}
}
class Pagination: Decodable {
var users: [User]
var currentPage: Int
var totalPages: Int
enum ResultCodingKeys: String, CodingKey {
case users, currentPage, totalPages
}
required init(from decoder: Decoder) throws {
let objectsContainer = try decoder.container(keyedBy: ResultCodingKeys.self)
currentPage = try objectsContainer.decode(Int.self, forKey: .currentPage)
totalPages = try objectsContainer.decode(Int.self, forKey: .totalPages)
users = try objectsContainer.decode([User].self, forKey: .users)
}
}
class Pagination: Decodable {
var vets: [Vet]
var currentPage: Int
var totalPages: Int
enum ResultCodingKeys: String, CodingKey {
case vets, currentPage, totalPages
}
required init(from decoder: Decoder) throws {
let objectsContainer = try decoder.container(keyedBy: ResultCodingKeys.self)
currentPage = try objectsContainer.decode(Int.self, forKey: .currentPage)
totalPages = try objectsContainer.decode(Int.self, forKey: .totalPages)
vets = try objectsContainer.decode([Vet].self, forKey: .vets)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.