Skip to content

Instantly share code, notes, and snippets.

@alexnikol
Created August 17, 2020 07:50
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/6849caec6c33ccf8bb8718cfe8ae7ae1 to your computer and use it in GitHub Desktop.
Save alexnikol/6849caec6c33ccf8bb8718cfe8ae7ae1 to your computer and use it in GitHub Desktop.
Default Pagination Realization
class Pagination: Decodable {
var cars: [Car]
var currentPage: Int
var totalPages: Int
enum ResultCodingKeys: String, CodingKey {
case cars, 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)
cars = try objectsContainer.decode([Car].self, forKey: .cars)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment