Search
 
SCRIPT & CODE EXAMPLE
 

SWIFT

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
    }

}
Comment

PREVIOUS NEXT
Code Example
Swift :: Swift Bitwise NOT Operator 
Swift :: Swift self property 
Swift :: swift constants 
Swift :: disable trailing swipe action swift 
Swift :: single word search swift 
Swift :: swift view controller background image 
Swift :: Swift Protocol To Calculate Area 
Swift :: swift constraints 
Swift :: Swift Comparison Operators 
Swift :: swift closures 
Swift :: jsonserialization swift 
Swift :: Javascript Define Swift Class 
Swift :: swift animate constraint 
Swift :: xcode enable a button after a text field is filled 
Swift :: Swift Character 
Swift :: swift hashable 
Ruby :: how to I change the name of a column in rails 
Ruby :: iterate over string ruby 
Ruby :: eager load polymorphic rails 
Ruby :: how to create migration with uniqueness inrails 
Ruby :: rails form select 
Ruby :: ruby check if a file exists 
Ruby :: rails validate presence 
Ruby :: array string ruby 
Ruby :: add edit or --wait for rails credentials edit windows 
Ruby :: ruby class 
Ruby :: rails parse boolean 
Ruby :: rails devise valid_password 
Ruby :: generate dates using period rails 
Ruby :: rails string to html 
ADD CONTENT
Topic
Content
Source link
Name
4+5 =