Skip to content

Instantly share code, notes, and snippets.

@hassanvfx
Last active October 2, 2019 03:48
Show Gist options
  • Save hassanvfx/176a3a81588a8433a443aa14cbb2b618 to your computer and use it in GitHub Desktop.
Save hassanvfx/176a3a81588a8433a443aa14cbb2b618 to your computer and use it in GitHub Desktop.
import UIKit
import ObjectMapper
protocol APIResponse {
func items<K>(_ type:K.Type? )->[K]
}
extension APIResponse{
func items<K>(_ type:K.Type? = nil)->[K]{
return ([self] as? [K]) ?? []
}
}
extension Movie: APIResponse{}
struct APIResponseMovieList: Mappable,APIResponse {
var page: Int?
var results: [Movie]?
init?(map: Map) {
}
mutating func mapping(map: Map) {
page <- map["page"]
results <- map["results"]
}
func items<K>(_ type:K.Type? = nil)->[K]{
return (results as? [K]) ?? []
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment