使用 alamofire 对象映射器导致将我的 class 转换为 Any 时出错

using alamofire object mapper causing error for converting my class to Any

我在我的代码中使用了 Alamofire 和 AlamofireObjectMapper。

这是我要映射的 class:

    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"]

    }
}

我正在尝试在我的 API 结构中使用这个 class,如下所示:

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)
    }

}

然后我得到这个错误:

无法将类型“(DataResponse) -> Void”的值转换为预期的参数类型“(DataResponse) -> Void”

如何修复这个编译错误?

你应该使用

_ = Alamofire.request(Path.mainPageCollections.url, method: .get, parameters: nil, encoding: URLEncoding.default).responseObject(completionHandler: callback)

然后您可以确认基本可映射协议