Skip to content

Instantly share code, notes, and snippets.

@kevingriffin
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kevingriffin/de4a78898e7e3978b991 to your computer and use it in GitHub Desktop.
Save kevingriffin/de4a78898e7e3978b991 to your computer and use it in GitHub Desktop.
Swift NSArray indexOfObject (Is there no better way to do this?)
func indexOfObject<T: Equatable>(array: Array<T>, object: T) -> Int? {
var i: Int
for i = 0; i < array.count; ++i {
if (array[i] == object) {
return i
}
}
return nil
}
@rajeevsharma2811
Copy link

Currently using in Swift 1.2. I am getting "Overload" error message. Am I doing something wrong?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment