JSONResponseSerializer& Alamofire4遇到麻烦HTTPURLResponse Swift 3.0

时间:2016-10-03 19:05:15

标签: ios swift xcode swift3 alamofire

自从我更新了Alamofire后,我收到了错误:类型请求没有成员JSONResponseSerializer 无法调用非功能类型的值HTTPURLResponse

我已经将Response切换为DataResponse,但我仍然收到错误。

enter image description here

代码:

extension Alamofire.Request {
    func responseUserEventsArray(_ completionHandler: @escaping (DataResponse<UserEventsWrapper>) -> Void) -> Self {
        let responseSerializer = DataResponseSerializer<UserEventsWrapper> { request, response, data, error in
            guard error == nil else
            {
                return .failure(error!)
            }
            guard let responseData = data else {
                return .failure(AFError.responseSerializationFailed(reason: .inputDataNil))

            }

            let JSONResponseSerializer = Request.JSONResponseSerializer(options: .allowFragments)
            let result = JSONResponseSerializer.serializeResponse(request, response, responseData, error)

            switch result {
            case .Success(let value):
                let json = JSON(value)
                let wrapper = UserEventsWrapper()

                wrapper.next = json["eventhistory"]["next_page_url"].stringValue
                wrapper.previous = json["eventhistory"]["prev_page_url"].stringValue
                wrapper.count = json["eventhistory"]["total"].intValue

                var allUserEvents:Array = Array<UserEvents>()
                print(json)
                let results = json["eventhistory"]["data"]
                print(results)

                for jsonAds in results
                {
                    print(jsonAds.1)
                    let adsData = UserEvents(json: jsonAds.1, id: Int(jsonAds.0))
                    allUserEvents.append(adsData)
                }
                wrapper.usereventsitems = allUserEvents
                return .success(wrapper)
            case .Failure(let error):
                return .Failure(error)
            }
        }

        return response(responseSerializer: responseSerializer,completionHandler: completionHandler)
    }
}

1 个答案:

答案 0 :(得分:4)

EDITED

更改

Request.JSONResponseSerializerDataRequest.jsonResponseSerializer

extension Alamofire.Requestextension Alamofire.DataRequest - Mat0

.success.failure - FranMowinckel