Horje
how to print body moya swift Code Example
how to print body moya swift
struct VerbosePlugin: PluginType {
    let verbose: Bool

    func prepare(_ request: URLRequest, target: TargetType) -> URLRequest {
        #if DEBUG
        if let body = request.httpBody,
           let str = String(data: body, encoding: .utf8) {
            if verbose {
                print("request to send: \(str))")
            }
        }
        #endif
        return request
    }

    func didReceive(_ result: Result<Response, MoyaError>, target: TargetType) {
        #if DEBUG
        switch result {
        case .success(let body):
            if verbose {
                print("Response:")
                if let json = try? JSONSerialization.jsonObject(with: body.data, options: .mutableContainers) {
                    print(json)
                } else {
                    let response = String(data: body.data, encoding: .utf8)!
                    print(response)
                }
            }
        case .failure( _):
            break
        }
        #endif
    }

}




Swift

Related
transform string to url swift Code Example transform string to url swift Code Example
protocol oriented programming swift github Basic Code Example protocol oriented programming swift github Basic Code Example
swift paged scrollview get current page Code Example swift paged scrollview get current page Code Example
swift md5 cryptokit Code Example swift md5 cryptokit Code Example
continue keyword in swift language Code Example continue keyword in swift language Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
7