---
title: NSMachPort
framework: foundation
role: symbol
role_heading: Class
path: foundation/nsmachport
---

# NSMachPort

A port that can be used as an endpoint for distributed object connections (or raw messaging).

## Declaration

```swift
class NSMachPort
```

## Overview

Overview NSMachPort is a subclass of Port that wraps a Mach port, the fundamental communication port in macOS. NSMachPort allows for local (on the same machine) communication only. A companion class, SocketPort, allows for both local and remote distributed object communication, but may be more expensive than NSMachPort for the local case. To use NSMachPort effectively, you should be familiar with Mach ports, port access rights, and Mach messages. See the Mach OS documentation for more information. note: NSMachPort conforms to the NSCoding protocol, but only supports coding by an NSPortCoder. Port and its subclasses do not support archiving.

## Topics

### Creating and Initializing

- [port(withMachPort:)](foundation/nsmachport/port(withmachport:).md)
- [port(withMachPort:options:)](foundation/nsmachport/port(withmachport:options:).md)
- [init(machPort:)](foundation/nsmachport/init(machport:).md)
- [init(machPort:options:)](foundation/nsmachport/init(machport:options:).md)

### Getting the Mach Port

- [machPort](foundation/nsmachport/machport.md)

### Scheduling the Port on a Run Loop

- [remove(from:forMode:)](foundation/nsmachport/remove(from:formode:).md)
- [schedule(in:forMode:)](foundation/nsmachport/schedule(in:formode:).md)

### Getting and Setting the Delegate

- [delegate()](foundation/nsmachport/delegate().md)
- [setDelegate(_:)](foundation/nsmachport/setdelegate(_:).md)

### Constants

- [NSMachPort.Options](foundation/nsmachport/options.md)

## Relationships

### Inherits From

- [Port](foundation/port.md)

### Conforms To

- [CVarArg](swift/cvararg.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Hashable](swift/hashable.md)
- [NSCoding](foundation/nscoding.md)
- [NSCopying](foundation/nscopying.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)
- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)

## See Also

### Legacy

- [NSMachPortDelegate](foundation/nsmachportdelegate.md)
- [MessagePort](foundation/messageport.md)
- [PortDelegate](foundation/portdelegate.md)
- [PortMessage](foundation/portmessage.md)
- [NSProtocolChecker](foundation/nsprotocolchecker.md)
