indices(of:)
Returns the indices of all the elements that are equal to the given element.
Declaration
func indices(of element: Self.Element) -> RangeSet<Self.Index>Parameters
- element:
An element to look for in the collection.
Return Value
A set of the indices of the elements that are equal to element.
Discussion
For example, you can use this method to find all the places that a particular letter occurs in a string.
let str = "Fresh cheese in a breeze"
let allTheEs = str.indices(of: "e")
// str[allTheEs].count == 7