Is it possible to create an NSXPCInterface using a generic parameter?

133 Views Asked by At

I'm attempting to make a generic wrapper around an NSXPCConnection, and I'm really struggling. I believe the issue is the use of an ObjC Protocol type by NSXPCInterface. I cannot find a way to work with it using generics, but seems like it could be possible.

Here's what I've tried:

@objc protocol ExampleXPCProtocol {
    func doThing()
}

class GenericXPCInterface<Remote: Protocol> {
    private let connection: NSXPCConnection

    init(serviceName name: String) {
        self.connection = NSXPCConnection(serviceName: name)

        // this line works
        connection.remoteObjectInterface = NSXPCInterface(with: ExampleXPCProtocol.self)

        // this line produces the error:
        // Cannot convert value of type 'Remote.Type' to expected argument type 'Protocol'
        connection.remoteObjectInterface = NSXPCInterface(with: Remote.self)
    }
}

For reference, the signature for that NSXPCInterface initializer is:

init(with protocol: Protocol)
0

There are 0 best solutions below