Reputation: 2872
I'm using a generic typealias to create closures. However I'm limited to a finite number of generic parameters.
typealias Closure<T> = (T) -> Void
This works:
func foo(closure: Closure<(String, Bool)>) {}
This doesn't:
func foo(closure: Closure<String, Bool>) {}
Any way to create generic variadic parameters?
Upvotes: 2
Views: 508
Reputation: 299703
What you're describing isn't variadic (that would be Closure<String, ...>
, and Swift doesn't have either). What you're describing is very close to "splatted tuples" in Swift. (Swift would almost certainly call it "splatted type parameters" or something along those lines.) But no, Swift doesn't have this feature. The related feature that you would need in order to even use this ("splatted tuples") was removed recently, so even if you could create this, you almost certainly couldn't do anything with it because there'd be no way to call the closure.
Upvotes: 3