Generics with specialization

Thanks @ibex10 , the outcome is still the same when accessed via a protocol (default implementation would be picked instead of the specialized one).

let p1: any Raceable = Race(status: StatusB.idle)
print("p1.isAvailable: \(p1.isAvailable)")

Ideally I would want p1.isAvailable to be true but it takes the default implementation.

Reason for this is being explained in Calling a protocol with associatedType's method, doesn't always pick the same specialized generic implementation - #2 by xwu

However I can't seem to find a better implementation than to the one I posted originally to reliably use protocol and still match my expectation.

May be it is a design issue on my part, any alternate design are welcome as well.

1 Like