Swift Alamofire.request().responseObject不';t返回响应

Swift Alamofire.request().responseObject不';t返回响应,swift,request,response,alamofire,objectmapper,Swift,Request,Response,Alamofire,Objectmapper,我使用AlamoFileObject映射器扩展。我想得到回应,但失败了。我的tableLeague对象始终为nil,因为带有响应闭包的代码在 if response.result.issucess{ tableLeague=response.result.value }不调用)。我使用以下方法: let header = ["X-Auth-Token":"1231231"] static let sharedInstance = ServerAPI() private func getRequ

我使用AlamoFileObject映射器扩展。我想得到回应,但失败了。我的tableLeague对象始终为nil,因为带有响应闭包的代码在 if response.result.issucess{ tableLeague=response.result.value }不调用)。我使用以下方法:

let header = ["X-Auth-Token":"1231231"]

static let sharedInstance = ServerAPI()
private func getRequest(uri: String) -> DataRequest {
    return Alamofire.request(uri, method: .get, headers: header)
}

public func getTableLeague() -> TableLeague {
    var tableLeague: TableLeague?
    getRequest(uri: URL).responseObject { (response: DataResponse<TableLeague>) in
        if response.result.isSuccess {
            tableLeague = response.result.value
        }
    }
    return tableLeague!
}
我想这可能是因为响应还并没有出现,但我试图设置我还并没有出现的对象


有什么问题?我需要使用其他的完成处理程序?

请尝试按以下结构映射

class Response: Mappable {
    var success: Bool?
    var data: [Data]?

    required init?(_ map: Map) {
        mapping(map)
    }

    func mapping(map: Map) {
        success <- map["success"]
        data <- map["data"]
    }
}

class Data: Mappable {
    var uid: Int?
    var name: String?
    // add other field which you want to map        

    required init?(_ map: Map) {
        mapping(map)
    }

    func mapping(map: Map) {
        uid <- map["uid"]
        name <- map["name"]
    }
}
类响应:可映射{
var成功:布尔?
变量数据:[数据]?
必需的初始化(umap:map){
地图(地图)
}
func映射(映射:映射){

成功请添加有关您的问题的更多描述。我添加了更多描述。这意味着您的映射器类没有将响应映射到TableLeague类。请检查响应对象是否包含JSON对象。它是JSON对象{“\u links”:{“self”:{“href”:“},“competition”:{“href”:“}}”,联赛说明:“2016/17赛季英超联赛”,“比赛日”:18,“站姿”:[{…}
class Response: Mappable {
    var success: Bool?
    var data: [Data]?

    required init?(_ map: Map) {
        mapping(map)
    }

    func mapping(map: Map) {
        success <- map["success"]
        data <- map["data"]
    }
}

class Data: Mappable {
    var uid: Int?
    var name: String?
    // add other field which you want to map        

    required init?(_ map: Map) {
        mapping(map)
    }

    func mapping(map: Map) {
        uid <- map["uid"]
        name <- map["name"]
    }
}
let response = Mapper<Response>().map(responseObject)
if let id = response?.data?[0].uid {
    println(id)
}