I am getting following warning on Xcode using Alamofire
'responseJSON(queue:dataPreprocessor:emptyResponseCodes:emptyRequestMethods:options:completionHandler:)' is deprecated: responseJSON deprecated and will be removed in Alamofire 6. Use responseDecodable instead.
Here is the code: this code is working but give above warning.
let URL = "https://www.googleapis.com/youtube/v3/videos?id=\(videoId)&part=contentDetails&key=\(apiKey)"
var duration = String()
AF.request(URL).responseJSON { response in
if let result = response.value as? [String : Any],
let main = result["items"] as? [[String : Any]]{
for obj in main{
duration = (obj as NSDictionary).value(forKeyPath:"contentDetails.duration") as! String
completionHandler(duration, nil)
}
}
}
Any help with responseDecodable for the above will be greatly appreciated
According to your code the
Codablestructs areNowadays it's highly recommended to use the
async/awaitAPI of Alamofire, and rather than calling the completion handler multiple times just return an array of stringsYou have to wrap the function call in a
Taskand ado - catchblock.