---
title: "init(machServiceName:options:)"
framework: foundation
role: symbol
role_heading: Initializer
path: "foundation/nsxpcconnection/init(machservicename:options:)"
---

# init(machServiceName:options:)

Initializes an NSXPCConnection object to connect to a LaunchAgent or LaunchDaemon with a name advertised in a launchd.plist.

## Declaration

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

## Discussion

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 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 option.

## See Also

### Creating a connection

- [init(listenerEndpoint:)](foundation/nsxpcconnection/init(listenerendpoint:).md)
- [NSXPCConnection.Options](foundation/nsxpcconnection/options.md)
- [init(serviceName:)](foundation/nsxpcconnection/init(servicename:).md)
