firstRange(of:)
Returns the first found range of the type’s data buffer.
Declaration
func firstRange<D>(of data: D) -> Range<Self.Index>? where D : DataProtocolParameters
- data:
The data sequence to find.
Return Value
The range, if found, of the first match of the provided data sequence.
Discussion
An example of searching a data buffer converted from a string:
let data = "0123456789".data(using: .utf8)!
let pattern = "456".data(using: .utf8)!
let foundRange = data.firstRange(of: pattern)
// foundRange == Range(4..<7)