Skip to content

Commit

Permalink
Alamofire 6 fixes
Browse files Browse the repository at this point in the history
Fixed "responseJSON(queue:dataPreprocessor:emptyResponseCodes:emptyRequestMethods:options:completionHandler:)' is deprecated: responseJSON deprecated and will be removed in Alamofire 6"
  • Loading branch information
rursache authored Feb 25, 2022
1 parent f14feea commit d6ec200
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions Sources/Alamofire+Promise.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,22 @@ extension Alamofire.DataRequest {
}

/// Adds a handler to be called once the request has finished.
public func responseJSON(queue: DispatchQueue = .main, options: JSONSerialization.ReadingOptions = .allowFragments) -> Promise<(json: Any, response: PMKAlamofireDataResponse)> {
return Promise { seal in
responseJSON(queue: queue, options: options) { response in
switch response.result {
case .success(let value):
seal.fulfill((value, PMKAlamofireDataResponse(response)))
case .failure(let error):
seal.reject(error)
}
}
}
}
public func responseJSON(queue: DispatchQueue = .main, options: JSONSerialization.ReadingOptions = .allowFragments) -> Promise<(json: Any, response: PMKAlamofireDataResponse)> {
return Promise { seal in
responseData(queue: queue) { response in
switch response.result {
case .success(let dataValue):
do {
let json = try JSONSerialization.jsonObject(with: dataValue, options: options)
seal.fulfill((json, PMKAlamofireDataResponse(response)))
} catch {
seal.reject(error)
}
case .failure(let error):
seal.reject(error)
}
}
}

#if swift(>=3.2)
/**
Expand Down

0 comments on commit d6ec200

Please sign in to comment.