NestedResponse
@propertyWrapper
public struct NestedResponse<Response> where Response : Decodable
extension NestedResponse: Decodable
A property wrapper that wraps a nested response.
To support inheritance, which can be especially useful for pagination, use the property wrapper @NestedResponse to add nested responses.
While decoding the flat HTTP response will be applied recursively to all nested responses, therefore it is possible, that different nested responses access different values of the original HTTP response.
Example:
struct PaginatedResponse<NestedRequest: Request>: Decodable {
/// Header which indicates how many more elements are available
@ResponseHeader<DefaultHeaderStrategy> var totalElements
@NestedResponse var nested: NestedRequest
}
struct ListRequest: Request {
typealias Response = PaginatedResponse<ListResponse>
struct ListResponse: Decodable {
// see other examples
}
}
-
The wrapped value representing the nested response.
This property holds the nested response value that is managed by this property wrapper.
Declaration
Swift
public var wrappedValue: Response -
Initializes a new instance of
NestedResponsewith the specified wrapped value.Example usage:
@NestedResponse var nestedResponse: MyResponseTypeDeclaration
Swift
public init(wrappedValue: Response)Parameters
wrappedValueThe wrapped value representing the nested response.
-
Initializes a new instance of
NestedResponseby decoding from the given decoder.Throws
An error if the decoding process fails.Declaration
Swift
public init(from decoder: Decoder) throwsParameters
decoderThe decoder to read data from.
View on GitHub