<!--
{
  "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/init(name:context:)-oyjl",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "System"
    ],
    "preciseIdentifier" : "s:6System4MachO4PortVAaC12ReceiveRightVRszrlE4name7contextAEy_AGGs6UInt32V_Sutcfc"
  },
  "title" : "init(name:context:)"
}
-->

# init(name:context:)

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

## Discussion

This initializer aborts if name is MACH_PORT_NULL.

If the type of the right does not match the type T of Mach.Port
being constructed, the behavior is undefined.

The underlying port right will be automatically deallocated when
the Mach.Port object is destroyed.

---

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)