---
title: CFMachPort
framework: corefoundation
role: symbol
role_heading: Class
path: corefoundation/cfmachport
---

# CFMachPort

## Declaration

```swift
class CFMachPort
```

## Overview

Overview A CFMachPort object is a wrapper for a native Mach port (mach_port_t). Mach ports are the native communication channel for the macOS kernel. CFMachPort does not provide a function to send messages, so you primarily use a CFMachPort object if you need to listen to a Mach port that you obtained by other means. You can get a callback when a message arrives on the port or when the port becomes invalid, such as when the native port dies. To listen for messages you need to create a run loop source with CFMachPortCreateRunLoopSource(_:_:_:) and add it to a run loop with CFRunLoopAddSource(_:_:_:). important: If you want to tear down the connection, you must invalidate the port (using CFMachPortInvalidate(_:)) before releasing the runloop source and the Mach port object. To send data, you must use the Mach APIs with the native Mach port, which is not described here. Alternatively, you can use a CFMessagePort object, which can send arbitrary data. Mach ports only support communication on the local machine. For network communication, you have to use a CFSocket object.

## Topics

### Creating a CFMachPort Object

- [CFMachPortCreate(_:_:_:_:)](corefoundation/cfmachportcreate(_:_:_:_:).md)
- [CFMachPortCreateWithPort(_:_:_:_:_:)](corefoundation/cfmachportcreatewithport(_:_:_:_:_:).md)

### Configuring a CFMachPort Object

- [CFMachPortInvalidate(_:)](corefoundation/cfmachportinvalidate(_:).md)
- [CFMachPortCreateRunLoopSource(_:_:_:)](corefoundation/cfmachportcreaterunloopsource(_:_:_:).md)
- [CFMachPortSetInvalidationCallBack(_:_:)](corefoundation/cfmachportsetinvalidationcallback(_:_:).md)

### Examining a CFMachPort Object

- [CFMachPortGetContext(_:_:)](corefoundation/cfmachportgetcontext(_:_:).md)
- [CFMachPortGetInvalidationCallBack(_:)](corefoundation/cfmachportgetinvalidationcallback(_:).md)
- [CFMachPortGetPort(_:)](corefoundation/cfmachportgetport(_:).md)
- [CFMachPortIsValid(_:)](corefoundation/cfmachportisvalid(_:).md)

### Getting the CFMachPort Type ID

- [CFMachPortGetTypeID()](corefoundation/cfmachportgettypeid().md)

### Callbacks

- [CFMachPortCallBack](corefoundation/cfmachportcallback.md)
- [CFMachPortInvalidationCallBack](corefoundation/cfmachportinvalidationcallback.md)

### Data Types

- [CFMachPortContext](corefoundation/cfmachportcontext.md)

## Relationships

### Conforms To

- [Equatable](swift/equatable.md)
- [Hashable](swift/hashable.md)

## See Also

### Opaque Types

- [CFAllocator](corefoundation/cfallocator.md)
- [CFArray](corefoundation/cfarray.md)
- [CFAttributedString](corefoundation/cfattributedstring.md)
- [CFBag](corefoundation/cfbag.md)
- [CFBinaryHeap](corefoundation/cfbinaryheap.md)
- [CFBitVector](corefoundation/cfbitvector.md)
- [CFBoolean](corefoundation/cfboolean.md)
- [CFBundle](corefoundation/cfbundle.md)
- [CFCalendar](corefoundation/cfcalendar.md)
- [CFCharacterSet](corefoundation/cfcharacterset.md)
- [CFData](corefoundation/cfdata.md)
- [CFDate](corefoundation/cfdate.md)
- [CFDateFormatter](corefoundation/cfdateformatter.md)
- [CFDictionary](corefoundation/cfdictionary.md)
- [CFError](corefoundation/cferror.md)
