Matching a Swift protocol from an Objective-C Protocol instance

Viewed 572

I'm looking for a way to match dynamically an Objective-C Protocol instance with a corresponding Swift protocol.

I have a protocol defined in swift that is compatible with Objective-C:

@objc(YHMyProtocol) protocol MyProtocol { }

I try to perform the match, in a function:

public func existMatch(_ meta: Protocol) -> Bool {
    // Not working
    if meta is MyProtocol {
        return true
    }

    // Not working also
    if meta is MyProtocol.Protocol {
        return true
    }

    return false
}

This function is intended to be called from an Objective-C file:

if([Matcher existMatch:@protocol(YHMyProtocol)]) {
    /* Do Something */
}

The existMatch function always returns false.

I can not figure out how to solve this. Did I miss something in the implementation?

1 Answers
Related