. I understand why the error occurs; just because I create a specialised function, doesn't mean the default function is any less valid, and therefore it doesn't know which function to use.

It might also be possible to move the default implementation into an extension as well, but it would have to have type constraints which say something along the lines of 'any type which doesn't conform to

The actual problem I have is more complex, but I think this simplifies it down and correctly illustrates the problem I have. Is there a way of having default and specialised functionality depending on the conformance of

The easiest solution would be to simply use option #2 and just cast the result back to T? in order to bridge the gap with the fact that we can't cast T.self to a type of T.self that also conforms to TestProtocol.Type:

As defaultValue returns Self, this cast should never fail (we're using a conditional cast as the method returns an optional).

Although that being said, relying on runtime type-casting doesn't feel like a particularly nice solution to this problem. A possible way of achieving the overloading that you were trying to achieve in your option #1 is to use a protocol – allowing both static dispatching & overloading when the given associated type Something conforms to TestProtocol.

Perhaps not the most convenient solution, as it involves creating a new type – but as far as I'm aware the only way to achieve the conditional overloading behaviour you're after is through protocols. Although depending on the actual practical problem you're trying to solve, you may be able to integrate this into an already existing protocol.

Email codedump link for How to have default and specialised function in Swift depending on generic type?