Skip to content

Instantly share code, notes, and snippets.

@alexnikol
Created August 17, 2020 07:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexnikol/7c508123ea91a3934e1ed19d7559a5f3 to your computer and use it in GitHub Desktop.
Save alexnikol/7c508123ea91a3934e1ed19d7559a5f3 to your computer and use it in GitHub Desktop.
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