---
title: "port(withMachPort:)"
framework: foundation
role: symbol
role_heading: Type Method
path: "foundation/nsmachport/port(withmachport:)"
---

# port(withMachPort:)

Creates and returns a port object configured with the given Mach port.

## Declaration

```swift
class func port(withMachPort machPort: UInt32) -> Port
```

## Parameters

- `machPort`: The Mach port for the new port. This parameter should originally be of type mach_port_t.

## Return Value

Return Value An NSMachPort object that uses machPort to send or receive messages.

## Discussion

Discussion Creates the port object if necessary. Depending on the access rights associated with machPort, the new port object may be usable only for sending messages.

## See Also

### Related Documentation

- [Distributed Objects Programming Topics](apple-archive/documentation/Cocoa/Conceptual/DistrObjects.md)

### Creating and Initializing

- [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)
