<!--
{
  "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/withBorrowedName(body:)-8402i",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "System"
    ],
    "preciseIdentifier" : "s:6System4MachO4PortVAaC12ReceiveRightVRszrlE16withBorrowedName4bodyqd__qd__s6UInt32V_SutXE_tlF"
  },
  "title" : "withBorrowedName(body:)"
}
-->

# withBorrowedName(body:)

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

## Discussion

Take care when using this function; many operations consume rights.

If the right is consumed, behavior is undefined.

The body block may optionally return something, which will then be
returned to the caller of withBorrowedName.

---

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)