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

# port(withMachPort:options:)

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

## Declaration

```swift
class func port(withMachPort machPort: UInt32, options f: NSMachPort.Options = []) -> Port
```

## Parameters

- `machPort`: The Mach port for the new port. This parameter should originally be of type mach_port_t.
- `f`: Specifies options for what to do with the underlying port rights when the NSMachPort object is invalidated or destroyed. For a list of constants, see Mach Port Rights.

## 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

### Creating and Initializing

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