DataDecoder
open class DataDecoder
Decodes data from a network response.
Subspec: Utility/HTTPClient
Alamofire.request(request.endpoint).responseJSON { (response) in
completion(self.decoder.decodeData(response.data))
}
The data decoder can be used with network requests that return a Data object. The DataDecoder uses the APIErrorType to identify the network errors. If the object can not be deserialized the decoder will print out which coding key failed the the deserialization. Integration with the killswitch is also available if the api error received matched the unique killswitch or force update identifier.
-
JSON Decoder used to decode the object.
Declaration
Swift
private let decoder: JSONDecoder -
Optional killswitch provider used to check if the killswitch is active.
Declaration
Swift
private let killSwitchProvider: KillSwitchProvider?
-
Default initializer.
Declaration
Swift
public init(decoder: JSONDecoder = JSONDecoder(), killSwitchProvider: KillSwitchProvider? = nil)Parameters
decoderJSON Decoder to decode objects with.
killSwitchProviderOptional KillSwitchProvider.
-
Decodes the data into the desired result.
Declaration
Swift
public func decodeData<T>(_ data: Data?) -> Result<T> where T : DecodableParameters
dataData to deserialize.
Return Value
Desired result with the deserialized object.
-
Decodes the error if the decoder was unable to decode the object type requested.
Declaration
Swift
func decodeError<T>(_ data: Data, decodeError: Error) -> Result<T> where T : DecodableParameters
dataData of the request.
decodeErrorOptional error from the json decoder.
Return Value
The failed result of the request.
DataDecoder Class Reference