返回响应中的错误'无法调用非函数类型的值'NSHTTPURLResponse?'用Swift 3

时间:2017-02-27 11:02:16

标签: ios swift swift3 alamofire

我也从其他问题中读到答案,但无法解决:

我尝试了以下方式,但在行的相同错误 返回响应(responseSerializer:responseSerializer,completionHandler:completionHandler)

请帮助我们如何在以下方法中添加@escaping。

public func JSONResponseObject<T: ResponseObjectSerializable>(_ completionHandler: @escaping (DataResponse<T>) -> Void) -> Self {
    let responseSerializer = DataResponseSerializer<T> { request, response, data, error in
        guard error == nil else { return .failure(error!) }


        let jsonResponseSerializer = DataRequest.jsonResponseSerializer(options: .allowFragments)
        let result = jsonResponseSerializer.serializeResponse(request, response, data, nil)

        print("result: \(result.value)")

        switch result {
        case .success(let value):

            let json = JSON(value)
            print("JSON: \(json)")

            if let
                response = response,
                let responseObject = T(response: response, representation: value as AnyObject)
            {

                return .success(responseObject)
            } else {

                let error = Alamofire.AFError.ResponseSerializationFailureReason.jsonSerializationFailed(error: -6006 as! Error)

                return .failure(error as! Error)
            }
        case .failure(let error):

            let json = JSON(error)
            print("JSON: \(json)")

            return .failure(error)
        }
    }
    return response(responseSerializer: responseSerializer,completionHandler: completionHandler)
}

1 个答案:

答案 0 :(得分:0)

我现在以下列方式解决了

我在扩展程序Request {}

中设置扩展名DataRequest {}