<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.10.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/UnsafeBufferPointer/extracting(_:)-nivx",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:SRsRi_zrlE10extractingySRyxGSnySiGF"
  },
  "title" : "extracting(_:)"
}
-->

# extracting(_:)

Constructs a standalone buffer pointer over the items within the supplied
range of positions in the memory region addressed by this buffer pointer.

```
func extracting(_ bounds: Range<Int>) -> UnsafeBufferPointer<Element>
```

## Parameters

`bounds`

A valid range of indices within this buffer.

## Return Value

A new buffer pointer over the items at `bounds`.

## Discussion

The returned buffer’s first item is always at index 0; unlike buffer
slices, extracted buffers do not generally share their indices with the
original buffer pointer.

```
withUnsafeTemporaryAllocation(of: Int.self, capacity: 5) { buffer in
  buffer.initialize(repeating: 0)
  // buffer contains [0, 0, 0, 0, 0]
  let part = buffer.extracting(2 ..< 4)
  part[0] = 1
  part[1] = 2
  // buffer now contains [0, 0, 1, 2, 0]
}
```

When `Element` is copyable, the `extracting` operation is equivalent to
slicing the buffer then rebasing the resulting buffer slice:

```
let a = buffer.extracting(i ..< j)
let b = UnsafeBufferPointer(rebasing: buffer[i ..< j])
// `a` and `b` are now holding the same buffer
```

However, unlike slicing, the `extracting` operation remains available even
if `Element` happens to be noncopyable.

---

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)