2016-10-03 81 views
2

因爲我更新Alamofire我得到的錯誤:類型請求沒有成員JSONResponseSerializer不能調用非功能型HTTPURLResponseAlamofire4麻煩JSONResponseSerializer&HTTPURLResponse雨燕3.0

我已經切換響應的價值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) 
    } 
} 

回答

4

EDITED


變化

Request.JSONResponseSerializerDataRequest.jsonResponseSerializer

extension Alamofire.Requestextension Alamofire.DataRequest - MAT0

.success.failure - FranMowinckel

+3

和延伸Alamofire.Request分機Alamofire.DataRequest – Mat0

+3

而.success和.failure – FranMowinckel

+0

感謝再次幫助我!我會接受,當它解鎖:) – user2636197