-1

What i've tried was using a for-in loop, however that just cycles to the last value and gives me the rangeOfString for that value. It would be a lot to write the rangeOfString for all the values i want but if needed I don't mind. I just wanted to know if it was possible to use an array instead.

while true {
        let attempts = ["hello","goodbye"]
        for attempt in attempts{

             tru = attempt




        let range = text.rangeOfString("hello", options: [], range: searchRange)
Lorenzo
  • 3,293
  • 4
  • 29
  • 56
JoanDoe
  • 13
  • 3

1 Answers1

0

You can use map:

let text: NSString = "hello goodbye"
let attempts = ["hello", "goodbye"]
let ranges = attempts.map { text.rangeOfString($0, options: NSStringCompareOptions(rawValue: 0)) }
mixel
  • 25,177
  • 13
  • 126
  • 165