Reputation: 105
I'm using Alamofire and AlamofireObjectMapper in my code .
This is my class that im trying to map :
import ObjectMapper
import ObjectMapper
class ApplicationCollection: Mappable {
var title:String?
var name:String?
var collectionDescription:String?
var collectionId:Int!
var applications:[Application]?
required init?(map: Map) {
}
func mapping(map: Map) {
title <- map["title"]
collectionDescription <- map["description"]
collectionId <- map["id"]
applications <- map["applications"]
}
}
And I'm trying to use this class in my API struct like this :
import Foundation
import Alamofire
import AlamofireObjectMapper
struct API {
static let URL = "http://mysite.dev/"
enum Path {
case application(Int)
case mainPageCollections
var url:String {
let path:String
switch self {
case .application(let appId):
path = "applicatipn/\(appId)"
case .mainPageCollections:
path = "ApplicationCollections"
}
return API.URL + path
}
}
static func getRuleSetDetail(callback: @escaping (DataResponse<ApplicationCollection>) -> Void){
_ = Alamofire.request(Path.mainPageCollections.url, method: .get, parameters: nil, encoding: URLEncoding.default).responseJSON(completionHandler: callback)
}
}
and then I get this error :
Cannot convert value of type '(DataResponse) -> Void' to expected argument type '(DataResponse) -> Void'
How I can fix This compile error ?
Upvotes: 1
Views: 511
Reputation: 2352
You should use
_ = Alamofire.request(Path.mainPageCollections.url, method: .get, parameters: nil, encoding: URLEncoding.default).responseObject(completionHandler: callback)
then you can confrim to base mappable protocol
Upvotes: 1