Yep, I get that. I explored using an associatedtype in the protocol as well and what I'm attempting to do also didn't work.
protocol Foo {
associatedtype: State: ApplicationState
func update(_ value: State)
}
This gets me the API that I want, but the call site is where it breaks down. The type I'll be passing in is some ApplicationState and casting fails.
//Rough implementation
struct FeatureContainer<Feature: Foo> {
let feature: Foo
func receivedUpdate(_ value: some ApplicationState) {
feature.update(value as? Foo.State) <------ This casting will fail since the concrete type passed in is not concrete Foo.State,
but DOES conform to the protocol that constrained ` Foo.State` (protocol UserState).
But at this point, I don't know which `ApplicationState` protocol the `Foo.State` is using. (FreezeState or UserState).
}
}
I guessing what I want isn't possible to accomplish since the type could have multiple protocol conformances that also conform to ApplicationState.