<!--
{
  "availability" : [
    "Swift: 6.2.0 -",
    "Xcode: 26.0.0 -",
    "iOS: 2.0 -",
    "iPadOS: 2.0 -",
    "macCatalyst: 13.0 -",
    "macOS: 10.0 -",
    "tvOS: 9.0 -",
    "visionOS: 1.0 -",
    "watchOS: 2.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/Data/withUnsafeBytes(for:_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation",
      "Foundation"
    ],
    "preciseIdentifier" : "s:10Foundation4DataV09_Testing_A0E15withUnsafeBytes3for_x0C010AttachmentVyA2cG10AttachableADyHCg_G_xSWKXEtKlF"
  },
  "title" : "withUnsafeBytes(for:_:)"
}
-->

# withUnsafeBytes(for:_:)

```
func withUnsafeBytes<R>(for attachment: borrowing Attachment<Data>, _ body: (UnsafeRawBufferPointer) throws -> R) throws -> R
```

---

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)