Writing generic xpc client method

Currently, I’ve got multiple methods that create a different XPC connection.

I’d like to be able to pass the protocol/protocols as input argument and thus create a generic method the create different connections.

here’s my attempt to do so, notice the forwardProtocol and backwardProtocol. I’m not sure how can i pass them… Perhaps there’s a method that gets string and return it’s matching protocol ?

Thanks !

@implementation my_xpc_client
+(id) connectionWithName:(NSString *)connectionName withProtocol:(...)forwardProtocol withBackwardProtocol:... {
  static NSXPCConnection *config_connection = NULL;
  static id<forwardProtocol> proxy = NULL;
  NSXPCInterface *myXpcInterface = [NSXPCInterface interfaceWithProtocol:@protocol(forwardProtocol)];

  if (backwardProtocol) { 
    NSXPCInterface *backwardInterface =[NSXPCInterface interfaceWithProtocol:@protocol(backwardProtocol)];

    [myXpcInterface setInterface:backwardInterface
  myConnection = [[NSXPCConnection alloc] initWithMachServiceName:connectionName options:0];
  myConnection.remoteObjectInterface = myXpcInterface;
  myConnection.invalidationHandler = ^{
    NSLog(@"connection invalidated.");
    config_connection = nil;
    proxy = nil;
  proxy = [myConnection synchronousRemoteObjectProxyWithErrorHandler:^(NSError * _Nonnull error) {
    NSLog(@"connection error: %s", [[error description] UTF8String]);
    config_connection = nil;
    proxy = nil;
  [myConnection resume];

  NSLog(@"connection established.");