import Foundation import Alamofire extension Alamofire.DataRequest { func responseDebugPrint() -> Self { return responseJSON() { response in if let JSON = response.result.value, let JSONData = try? JSONSerialization.data(withJSONObject: JSON, options: .prettyPrinted), let prettyString = NSString(data: JSONData, encoding: String.Encoding.utf8.rawValue) { print(prettyString) } else if let error = response.result.error { print("Error Debug Print: \(error.localizedDescription)") } } } } /****************************/ // Use case : We can use like this /****************************/ Alamofire.request(...).responseObject { //Code here }.responseDebugPrint() /************* OR ***************/ Alamofire.request(url, method: .get, parameters: parameters, headers: headers) .validate() .responseObject { (response: DataResponse) in self.pendingRequests.removeValue(forKey: endPoint) completion!(response) if(NetworkConfig.loggingEnable) { debugPrint("************* printing REQUEST parameter and Headers *************") debugPrint("RESPONSE : \(response.debugDescription)") } }.responseDebugPrint()