<!--
{
  "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/Slice/init(base:bounds:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:s5SliceV4base6boundsAByxGx_Sny5IndexQzGtcfc"
  },
  "title" : "init(base:bounds:)"
}
-->

# init(base:bounds:)

Creates a view into the given collection that allows access to elements
within the specified range.

```
init(base: Base, bounds: Range<Base.Index>)
```

## Parameters

`base`

The collection to create a view into.

`bounds`

The range of indices to allow access to in the new slice.

## Discussion

It is unusual to need to call this method directly. Instead, create a
slice of a collection by using the collection’s range-based subscript or
by using methods that return a subsequence.

```
let singleDigits = 0...9
let subSequence = singleDigits.dropFirst(5)
print(Array(subSequence))
// Prints "[5, 6, 7, 8, 9]"
```

In this example, the expression `singleDigits.dropFirst(5))` is
equivalent to calling this initializer with `singleDigits` and a
range covering the last five items of `singleDigits.indices`.

---

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)