<!--
{
  "availability" : [
    "macOS: 13.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSXPCListener/setConnectionCodeSigningRequirement(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSXPCListener(im)setConnectionCodeSigningRequirement:"
  },
  "title" : "setConnectionCodeSigningRequirement(_:)"
}
-->

# setConnectionCodeSigningRequirement(_:)

Sets the code signing requirement for connections to this listener.

```
func setConnectionCodeSigningRequirement(_ requirement: String)
```

## Parameters

`requirement`

A string that describes requirements expected of the connection peer. See [Code Signing Guide](https://developer.apple.com/library/archive/documentation/Security/Conceptual/CodeSigningGuide/) for more information on the code signing format.

## Discussion

Use this method to enforce a code-signing requirement on incoming XPC connections.

The following example shows how a listener can ensure that the XPC client service on the other end of a connection has a specific entitlement.

```objc
- (BOOL)listener:(NSXPCListener *)listener shouldAcceptNewConnection:(NSXPCConnection *)newConnection {
    MyExportedObject *e = [[MyExportedObject new] autorelease];
    newConnection.exportedObject = e;
    newConnection.exportedInterface = [NSXPCInterface interfaceWithProtocol:@protocol(MyExportedObjectProtocol)];
    
    // This is an entitlement that must exist on the incoming connection's app signature
    [newConnection setCodeSigningRequirement:@"entitlement [com.example.testentitlement] exists"];
    [newConnection resume];

    return YES;
}
```

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)