---
title: "lastRange(of:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/dataprotocol/lastrange(of:)"
---

# lastRange(of:)

Returns the last found range of the type’s data buffer.

## Declaration

```swift
func lastRange<D>(of data: D) -> Range<Self.Index>? where D : DataProtocol
```

## Parameters

- `data`: The data sequence to find.

## Return Value

Return Value The range, if found, of the last match of the provided data sequence.

## Discussion

Discussion An example of searching a data buffer for the last match: let data: [UInt8] = [0, 1, 2, 3, 0, 1, 2, 3] let pattern: [UInt8] = [2, 3]

let match = data.lastRange(of: pattern) // match == 6..<8

## See Also

### Searching Within Data

- [firstRange(of:)](foundation/dataprotocol/firstrange(of:).md)
- [firstRange(of:in:)](foundation/dataprotocol/firstrange(of:in:).md)
- [lastRange(of:in:)](foundation/dataprotocol/lastrange(of:in:).md)
