Swift find all occurrences of a substring : <p>I have an extension here of the String class in Swift that returns the index of the first letter of a given substring.</p>

<p>Can anybody please help me make it so it will return an array of all occurrences instead of just the first one?</p>

<p>Thank you.    </p>

<pre><code>extension String {
    func indexOf(string : String) -&gt; Int {
        var index = -1
        if let range = self.range(of : string) {
            if !range.isEmpty {
                index = distance(from : self.startIndex, to : range.lowerBound)
            }
        }
        return index
    }
}
</code></pre>

<p>For example instead of a return value of <code>50</code> I would like something like <code>[50, 74, 91, 103]</code></p>
