I want to create a custom class for Alamofire so I will be able to call the request over and over again in various classes. In order to do that I need to pass the model class that extends to Mappable in DataResponse. But I got many errors.
This is my current code in the custom class:
func callAPI<T: Mappable>(response: T){
Alamofire.request(url!, method: .post, parameters: nil, encoding: JSONEncoding.default, headers: nil).responseObject { (response: DataResponse<T>) in
let result = response.result.value as! BaseData
}
}
And this is my code when i call the method:
func data() {
let manager = ManagerData(url: url)
manager.callAPI(response: Model.self)
}
This is my Model class:
class Model: BaseData {
var point: String?
var list: [Voucher]?
override func mapping(map: Map) {
super.mapping(map: map)
totalPoint <- map["TOTAL_POINT"]
list <- map["VOUCHER"]
}
}
class BaseData: Mappable {
var status: String?
var message: String?
required init() {
}
required init?(map: Map) {
}
func mapping(map: Map) {
status <- map["STATUS"]
message <- map["MESSAGE"]
}
}
On manager.callAPI(response: Model.self)
error is Argument type Model.Type does not conform to expected type Mappable
.
Any suggestion how to do it?