<!--
{
  "availability" : [
    "macOS: 10.8.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSXPCConnection/init(machServiceName:options:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSXPCConnection(im)initWithMachServiceName:options:"
  },
  "title" : "init(machServiceName:options:)"
}
-->

# init(machServiceName:options:)

Initializes an [`NSXPCConnection`](/documentation/Foundation/NSXPCConnection) object to connect to a LaunchAgent or LaunchDaemon with a name advertised in a `launchd.plist`.

```
init(machServiceName name: String, options: NSXPCConnection.Options = [])
```

## Discussion

For example, if an agent is managed with `launchd` and has a `launchd.plist` in `~/Library/LaunchAgents`, this method would create a connection to that agent. The agent should use [`NSXPCListener`](/documentation/Foundation/NSXPCListener) to wait for new connections.

If the connection is being made to a process that is running in a privileged Mach bootstrap context (for example, a daemon started by a `launchd` property list in `/Library/LaunchDaemons`), then pass the [`NSXPCConnection`](/documentation/Foundation/NSXPCConnection) option.

---

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)