I am using AlamofireObjectMapper I need to create a func that accepts such a generic parameter:
func doSomething < T : BaseMappable > (myCustomClass : T)
{
Alamofire.request("url", method: .get, parameters: nil, encoding: JSONEncoding.default, headers: APIKeys().AuthorizedHeader).responseObject(completionHandler: { ( response :DataResponse<T>) in
let data = response.result.value
if let array = data?.objects
{
for ar in array
{
self.allPromotions.append(ar)
}
}
})
}
but iam gets an error:
Using the undeclared type 'myCustomClass' change how you guys reply to me in the comments, I fixed a fixed error, but I got another error when iam tries to call this method
I called such a method
doSomething(myCustomClass: Promotions)
but I got another error
The argument type 'Promotions.Type' does not match the expected type 'BaseMappable'
and here is my class Promotions
import ObjectMapper
class Promotions : Mappable {
var id:Int?
var workshop_id:Int?
var title:String?
var desc:String?
var start_date:String?
var expire_date:String?
var type:String?
var objects = [Promotions]()
required init?(map: Map){
}
func mapping(map: Map) {
id <- map["id"]
workshop_id <- map["workshop_id"]
title <- map["title"]
desc <- map["desc"]
start_date <- map["start_date"]
expire_date <- map["expire_date"]
type <- map["type"]
objects <- map["promotions"]
}
}
How can i fix it
source
share