In my project (written in Swift 3) I want to retrieve index of an element from array using indexOf(_:)
method (existed in Swift 2.2), but I cannot find any replacement for that.
Is there any good replacement for that method in Swift 3 or anything that act similar?
Update
I forget to mention that I want to search in custom object. In code completion I haven't got any hints when typing 'indexof'. But when I try to get index of build in type like Int
code completion works and I could use index(of:)
method.
This worked for me in Swift 3 without an extension:
indexOf(_:)
has been renamed toindex(of:)
for types that conform toEquatable
. You can conform any of your types toEquatable
, it's not just for built-in types:indexOf(_:)
that takes a closure has been renamed toindex(where:)
:Didn't work for me in Swift 3 XCode 8 until I gave my class an extension.
For example: