<!--
{
  "availability" : [
    "iOS: 17.4.0 -",
    "iPadOS: 17.4.0 -",
    "macCatalyst: 17.4.0 -",
    "macOS: 14.4.0 -",
    "tvOS: 17.4.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 10.4.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "System",
  "identifier" : "/documentation/System/Mach/Port",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "System"
    ],
    "preciseIdentifier" : "s:6System4MachO4PortV"
  },
  "title" : "Mach.Port"
}
-->

# Mach.Port

```
struct Port<RightType> where RightType : MachPortRight
```

## Topics

### Initializers

[`init()`](/documentation/System/Mach/Port/init())

Allocate a new Mach port with a receive right, creating a
Mach.Port<Mach.ReceiveRight> to manage it.

[`init(name: mach_port_name_t)`](/documentation/System/Mach/Port/init(name:))

Transfer ownership of an existing unmanaged Mach port right into a
`Mach.Port` by name.

[`init(name: mach_port_name_t, context: mach_port_context_t)`](/documentation/System/Mach/Port/init(name:context:)-14mp9)

Transfer ownership of an existing, unmanaged, but already guarded,
Mach port right into a Mach.Port by name.

[`init(name: mach_port_name_t, context: mach_port_context_t)`](/documentation/System/Mach/Port/init(name:context:)-oyjl)

Transfer ownership of an existing, unmanaged, but already guarded,
Mach port right into a Mach.Port by name.

### Instance Properties

[`var makeSendCount: mach_port_mscount_t`](/documentation/System/Mach/Port/makeSendCount)

Access the make-send count.

### Instance Methods

[`func copySendRight() throws -> Mach.Port<Mach.SendRight>`](/documentation/System/Mach/Port/copySendRight())

Create another send right from a given send right.

[`func makeSendOnceRight() -> Mach.Port<Mach.SendOnceRight>`](/documentation/System/Mach/Port/makeSendOnceRight())

Create a send-once right for a given receive right.

[`func makeSendRight() -> Mach.Port<Mach.SendRight>`](/documentation/System/Mach/Port/makeSendRight())

Create a send right for a given receive right.

[`func relinquish() -> mach_port_name_t`](/documentation/System/Mach/Port/relinquish()-241tg)

Transfer ownership of the underlying port right to the caller.

[`func relinquish() -> (name: mach_port_name_t, context: mach_port_context_t)`](/documentation/System/Mach/Port/relinquish()-70vbe)

Transfer ownership of the underlying port right to the caller.

[`func relinquish() -> mach_port_name_t`](/documentation/System/Mach/Port/relinquish()-74amu)

Transfer ownership of the underlying port right to the caller.

[`func relinquish() -> (name: mach_port_name_t, context: mach_port_context_t)`](/documentation/System/Mach/Port/relinquish()-9lm56)

Transfer ownership of the underlying port right to the caller.

[`func unguardAndRelinquish() -> mach_port_name_t`](/documentation/System/Mach/Port/unguardAndRelinquish())

Remove guard and transfer ownership of the underlying port right to
the caller.

[`func withBorrowedName<ReturnType>(body: (mach_port_name_t, mach_port_context_t) -> ReturnType) -> ReturnType`](/documentation/System/Mach/Port/withBorrowedName(body:)-4d4iq)

Borrow access to the port name in a block that can perform
non-consuming operations.

[`func withBorrowedName<ReturnType>(body: (mach_port_name_t, mach_port_context_t) -> ReturnType) -> ReturnType`](/documentation/System/Mach/Port/withBorrowedName(body:)-8402i)

Borrow access to the port name in a block that can perform
non-consuming operations.

[`func withBorrowedName<ReturnType>(body: (mach_port_name_t) -> ReturnType) -> ReturnType`](/documentation/System/Mach/Port/withBorrowedName(body:)-9v68k)

Borrow access to the port name in a block that can perform
non-consuming operations.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)