Say I have a Fooable protocol:
protocol Fooable {}
Now I need to work with the Fooable type in a generic function:
func fooingAround<FooableType: Fooable>(withType: FooableType.Type) {}
This works fine when I just call a function with type Fooable :
struct Foo: Fooable {} fooingAround(Foo.self)
However, I need to get the type Fooable , which I pass to the function from another place. Here the compiler does not work:
let fooableType: Fooable.Type = // obtain from somewhere else fooingAround(fooableType) // compiler error: "Cannot invoke 'fooingAround' with an argument list of type '(Fooable.Type)'"
In particular, I get Fooable.Type from an enumeration that describes the API endpoints, where each endpoint is represented by a different Fooable class.
I assume that the problem arises because I am dynamically getting the type, so there can be no strong input at compile time.
Is there any way around this?
source share