1

Is there a "better"(less verbose) way of doing this?

var found: Int?  
for i in 0...myArray-1 {
    if myArray[i] == 3 {
        found = i
    }
}

similar to

let i = find(myArray, "1")

but for Int ?

This question is slightly "different" than How to find index of list item in Apple's swift? because it directly address the find function for Int, instead of String. Granted, the only difference is the title and pointing out that you can remove the quotation marks to get Int.

Community
  • 1
  • 1
KML
  • 2,302
  • 5
  • 26
  • 47

1 Answers1

7

Here's an Int example

let myArray = [1, 2, 3]
var i = find(myArray, 2)

Good luck

Mustafa Ibrahim
  • 1,110
  • 1
  • 9
  • 17