Ok, I'm stumped here. Am I holding this wrong somehow? I get compiler errors, or undefined symbol errors, when trying to access destructured tuples returned from using a parameter pack function. Simple repro below:
import Foundation
struct ResponseTuple<each Response: QueryResponseProtocol> {
let responses: (repeat each Response)
}
protocol QueryResponseProtocol: Equatable {}
protocol QueryStateAccessing {
func values<each T: QueryResponseProtocol>(for types: repeat (each T).Type) throws -> (repeat each T)
// If I instead use a ResponseTuple type for the return, then the compiler is happy when I access the properties
// func values<each T: QueryResponseProtocol>(for types: repeat (each T).Type) throws -> ResponseTuple<repeat each T>
}
struct ShippingResponse: QueryResponseProtocol {
let service: String
}
struct AspectsResponse: QueryResponseProtocol {
let aspects: [String]
}
struct PricingResponse: QueryResponseProtocol {
let price: Decimal
}
struct ShippingServiceRequest {
typealias ResponseModel = ShippingResponse
init(queryState: QueryStateAccessing) throws {
let (pricingResponse, aspectsResponse) = try queryState.values(for: PricingResponse.self, AspectsResponse.self)
_ = pricingResponse.price // this works fine
// _ = aspectsResponse.aspects // this is a compiler error - Undefined symbol
// single value is a compiler error
// let (pricingResponse) = try queryState.values(for: PricingResponse.self) // this is a compiler error
// this is a compiler error
// let results = try queryState.values(for: PricingResponse.self, AspectsResponse.self)
// _ = results.0
// compiler happy when use the ResponseTuple type approach
// let responseTuple = try queryState.values(for: PricingResponse.self, AspectsResponse.self)
// _ = responseTuple.responses.1
}
}