Response.md

March 13, 2019 ยท View on GitHub

Response

Response of a request which you can decode to JsonObject or Model.

Decode to Dictionary

HTTPBinNetwork.request(GetDictionaryRequest()) { (response) in
    if let dictionary = response.dataDictionary {
                        
    }
    else if let error = response.error {
        //show error
    }
}

Decode to Array

HTTPBinNetwork.request(GetArrayRequest()) { (response) in
    if let array = response.dataArray {
                        
    }
    else if let error = response.error {
        //show error
    }
}

Decode to String

HTTPBinNetwork.request(GetStringRequest()) { (response) in
    if let string = response.dataString {
                        
    }
    else if let error = response.error {
        //show error
    }
}

Decode to Model

struct User: Decodable { //Swift 4 Codable
    var id: Int
    var name: String
    var token: String
}

HTTPBinNetwork.request(UserRequest()) { (response) in
    if let user = response.decode(to: User.self) {
                        
    }
    else if let error = response.error {
        //show error
    }
}