How can I test a type (not an instance) for Equatable?

104 Views Asked by At

From another question here on SO about testing for protocol conformance, this is the solution...

public class Foo<TItem> {

    final public var items:[TItem] = [] {
        didSet{

            // This is allowed
            if TItem.self is SomeProtocol.Type {

            }
            else{
            }
        }
    }
}

However, due to the self requirements, this isn't allowed...

public class Foo<TItem> {

    final public var items:[TItem] = [] {
        didSet{

            // This is NOT allowed
            if TItem.self is Equatable.Type {
                ...update based on eqality...
            }
            else{
                ...process en masse since we can't check for equality...
            }
        }
    }
}

So how can I write the above so I can check for equatable conformance and process it accordingly?

0

There are 0 best solutions below