I'm new to Swift and I'm trying to upgrade some old Swift code. I'm getting the below warning:
'responseJSON(queue:dataPreprocessor:emptyResponseCodes:emptyRequestMethods:options:completionHandler:)' is deprecated: responseJSON deprecated and will be removed in Alamofire 6. Use responseDecodable instead.
...in the below code:
extension Alamofire.DataRequest {
func json(_ options: JSONSerialization.ReadingOptions = .allowFragments, successHandler: ((Any?) -> Void)? = nil, failureHandler: ((AFDataResponse<Any>) -> Void)? = nil) -> Self {
return responseJSON() {
response in
if UtilityService.ensureSuccessful(response, failureHandler: { failureHandler?(response) }) {
successHandler?(response.value)
}
NetworkActivityManager.sharedInstance.decrementActivityCount()
}
}
}
If I replace responseJSON with responseDecodable, I get this error:
Generic parameter 'T' could not be inferred
What do I need to do to update this code?
Decodable
type and provide that type toresponseDecodable
. Then update your surrounding methods to use a generic rather thanAny
. – RevenantCodable
, Swift Feature for decoding JSON? If not, you can still useresponseData()
and call yourselfJSONSerialization.jsonObject(with:options:)
on it. – Genova