Get index of the element in Swift

0

I'm trying to use the indexOf to know the index of an object inside the array but I do not know which parameter (s) to pass.

My code:

/// Struct that define the track model                     
asked by anonymous 16.12.2015 / 18:33

1 answer

3

You have to specify which property you want to compare, as in your example the only property with a unique value is the name, I used it to compare.

if let index = playlist.tracks.indexOf({$0.songName == t.songName}){
  print(index)
}

Functional example : link

    
16.12.2015 / 18:51