<!--
{
  "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/Range/relative(to:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:Sn8relative2toSnyxGqd___t5IndexQyd__RszSlRd__lF"
  },
  "title" : "relative(to:)"
}
-->

# relative(to:)

Returns the range of indices described by this range expression within
the given collection.

```
func relative<C>(to collection: C) -> Range<Bound> where Bound == C.Index, C : Collection
```

## Parameters

`collection`

The collection to evaluate this range expression
in relation to.

## Return Value

A range suitable for slicing `collection`. The returned range
is *not* guaranteed to be inside the bounds of `collection`. Callers
should apply the same preconditions to the return value as they would
to a range provided directly by the user.

---

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)