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

# init(name:)

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

```
init(name: mach_port_name_t)
```

## Discussion

This initializer traps if `name` is `MACH_PORT_NULL`, or if `name` is
`MACH_PORT_DEAD` and the `RightType` is `Mach.ReceiveRight`.

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

The underlying port right will be automatically deallocated at the
end of the `Mach.Port` instance’s lifetime.

This initializer makes a syscall to guard the right.

---

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)