After trying it, I don't think this is what I'm looking for. I've tried a whole bunch of approaches involving tuples and enums and I keep finding roadblocks.
First I tried something like this:
enum DraftsURLParams {
case searchParams(query: String?, tag: String?)
}
func chooseBuilder(withInput someTuple: DraftsURLParams) -> (DraftsURLParams) ->Void {
switch someTuple {
case is DraftsURLParams.searchParams: //error: Enum case 'searchParams(query:tag:)' is not a member type of 'DraftsURLParams'
return funcOne
default:
return funcDefault
}
}
Then I realized oh yeah, the enum case is not interpreting (query: String?, tag: String?)
as a tuple. I think it's interpreting it as two associated values of type String?
named query:
and tag:
respectively. So then I tried something like this:
enum DraftsURLParams {
case searchParams = (query: "query", tag: "tag")
} //Raw value for enum case must be a literal
Doesn't work. Apparently a literal tuple doesn't count. See Enums with multiple raw values
In any case, even if raw values worked, it's not what I'm looking for since I want to be able to change the value of query and tag and not have them hard coded in.
For your approach of using an Array like [Variant]
, I like this idea but there are still some issues that I haven't wrapped my head around. This does satisfy my need for a heterogenous collection, but now I lose key value pairs. Plus arrays can change size.
The search continues.