当前位置 : 主页 > 手机开发 > 其它 >

swift – Alamofire v4使用未声明的类型响应

来源:互联网 收集:自由互联 发布时间:2021-06-11
当我更新到Alamofire v4时,我遇到了两个错误. 第一个是使用未声明的类型响应,我从这一行得到: func responseSavedAdsArray(_ completionHandler: (ResponseSavedAdsWrapper, NSError) - 第二个错误是使用我从此
当我更新到Alamofire v4时,我遇到了两个错误.

第一个是使用未声明的类型响应,我从这一行得到:

func responseSavedAdsArray(_ completionHandler: (Response<SavedAdsWrapper, NSError>) ->

第二个错误是使用我从此行获得的未解析的标识符ResponseSerializer:

let responseSerializer = ResponseSerializer<SavedAdsWrapper, NSError> { request, response, data, error in

这是我的所有代码:

extension Alamofire.Request {
    func responseSavedArray(_ completionHandler: (Response<SavedWrapper, NSError>) -> Void) -> Self {
        let responseSerializer = ResponseSerializer<SavedWrapper, NSError> { request, response, data, error in
            guard error == nil else {
                return .Failure(error!)
            }
            guard let responseData = data else {
                let failureReason = "Array could not be serialized because input data was nil."
                let userInfo: Dictionary<NSObject, AnyObject> = [NSLocalizedFailureReasonErrorKey: failureReason, Error.UserInfoKeys.StatusCode: response!.statusCode]
                let error = NSError(domain: Error.Domain, code: Error.Code.StatusCodeValidationFailed.rawValue, userInfo: userInfo)
                return .Failure(error)
            }

            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 = SavedWrapper()

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

                var allSaved:Array = Array<Saved>()
                print(json)
                let results = json["saveditems"]["data"]
                print(results)
                for jsonAdata in results
                {

                    let adsJData = SavedAds(json: jsonAdata.1, id: Int(jsonAdata.0))
                    allSaved.append(adsJData)
                }
                wrapper.saveditems = allSaved
                return .Success(wrapper)
            case .Failure(let error):
                return .Failure(error)
            }
        }

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

那是什么导致了这个?

先改变

func responseSavedAdsArray(_ completionHandler: (Response<SavedAdsWrapper, NSError>) ->

func responseSavedAdsArray(_ completionHandler: (DataResponse<SavedAdsWrapper>) ->

EDITED

let responseSerializer = ResponseSerializer<SavedAdsWrapper, NSError> { request, response, data, error in

let responseSerializer = DataResponseSerializer<SavedAdsWrapper> { request, response, data, error in
网友评论