<!--
{
  "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/UnsafeMutableBufferPointer/subscript(_:)-13u1d",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Subscript",
  "symbol" : {
    "kind" : "Instance Subscript",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:Srys5SliceVySryxGGSnySiGcip"
  },
  "title" : "subscript(_:)"
}
-->

# subscript(_:)

Accesses a contiguous subrange of the buffer’s elements.

```
subscript(bounds: Range<Int>) -> Slice<UnsafeMutableBufferPointer<Element>> { get nonmutating set }
```

## Parameters

`bounds`

A range of the buffer’s indices. The bounds of
the range must be valid indices of the buffer.

## Overview

The accessed slice uses the same indices for the same elements as the
original buffer uses. Always use the slice’s `startIndex` property
instead of assuming that its indices start at a particular value.

This example demonstrates getting a slice from a buffer of strings,
finding the index of one of the strings in the slice, and then using that
index in the original buffer.

```
var streets = ["Adams", "Bryant", "Channing", "Douglas", "Evarts"]
streets.withUnsafeMutableBufferPointer { buffer in
    let streetSlice = buffer[2..<buffer.endIndex]
    print(Array(streetSlice))
    // Prints "["Channing", "Douglas", "Evarts"]"
    let index = streetSlice.firstIndex(of: "Evarts")    // 4
    buffer[index!] = "Eustace"
}
print(streets.last!)
// Prints "Eustace"
```

> Note: Bounds checks for `bounds` are performed only in debug mode.

---

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)