Response

public final class Response : CustomDebugStringConvertible, Equatable

Represents a response to a MoyaProvider.request.

  • The status code of the response.

    Declaration

    Swift

    public let statusCode: Int
  • The response data.

    Declaration

    Swift

    public let data: Data
  • The original URLRequest for the response.

    Declaration

    Swift

    public let request: URLRequest?
  • The HTTPURLResponse object.

    Declaration

    Swift

    public let response: HTTPURLResponse?
  • Undocumented

    Declaration

    Swift

    public init(statusCode: Int, data: Data, request: URLRequest? = nil, response: HTTPURLResponse? = nil)
  • A text description of the Response.

    Declaration

    Swift

    public var description: String { get }
  • A text description of the Response. Suitable for debugging.

    Declaration

    Swift

    public var debugDescription: String { get }
  • Declaration

    Swift

    public static func == (lhs: Response, rhs: Response) -> Bool
  • Returns the Response if the statusCode falls within the specified range.

    Throws

    MoyaError.statusCode when others are encountered.

    Declaration

    Swift

    func filter<R>(statusCodes: R) throws -> Response where R : RangeExpression, R.Bound == Int

    Parameters

    statusCodes

    The range of acceptable status codes.

  • Returns the Response if it has the specified statusCode.

    Throws

    MoyaError.statusCode when others are encountered.

    Declaration

    Swift

    func filter(statusCode: Int) throws -> Response

    Parameters

    statusCode

    The acceptable status code.

  • Returns the Response if the statusCode falls within the range 200 - 299.

    Throws

    MoyaError.statusCode when others are encountered.

    Declaration

    Swift

    func filterSuccessfulStatusCodes() throws -> Response
  • Returns the Response if the statusCode falls within the range 200 - 399.

    Throws

    MoyaError.statusCode when others are encountered.

    Declaration

    Swift

    func filterSuccessfulStatusAndRedirectCodes() throws -> Response
  • Maps data received from the signal into an Image.

    Declaration

    Swift

    func mapImage() throws -> Image
  • Maps data received from the signal into a JSON object.

    Declaration

    Swift

    func mapJSON(failsOnEmptyData: Bool = true) throws -> Any

    Parameters

    failsOnEmptyData

    A Boolean value determining whether the mapping should fail if the data is empty.

  • Maps data received from the signal into a String.

    Declaration

    Swift

    func mapString(atKeyPath keyPath: String? = nil) throws -> String

    Parameters

    atKeyPath

    Optional key path at which to parse string.

  • Maps data received from the signal into a Decodable object.

    Declaration

    Swift

    func map<D>(_ type: D.Type, atKeyPath keyPath: String? = nil, using decoder: JSONDecoder = JSONDecoder(), failsOnEmptyData: Bool = true) throws -> D where D : Decodable

    Parameters

    atKeyPath

    Optional key path at which to parse object.

    using

    A JSONDecoder instance which is used to decode data to an object.