---
title: "init(machPort:)"
framework: foundation
role: symbol
role_heading: Initializer
path: "foundation/nsmachport/init(machport:)"
---

# init(machPort:)

Initializes a newly allocated NSMachPort object with a given Mach port.

## Declaration

```swift
init(machPort: UInt32)
```

## Parameters

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

## Return Value

Return Value Returns an initialized NSMachPort object that uses machPort to send or receive messages. The returned object might be different than the original receiver

## Discussion

Discussion Depending on the access rights for machPort, the new port may be able to only send messages. If a port with machPort already exists, this method deallocates the receiver, then retains and returns the existing port. This method is the designated initializer for the NSMachPort class.

## See Also

### Creating and Initializing

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