0

In my app I have an array of custom Objects.The structure of each row looks like this when I append them:

self.listOfParticipants.append(ParticipantInfo(participantUser: "userID", participantName: "userName", participantIconName: partiImage!))

I know that to return the index from a simple array of Strings I could do something like array.indexOf("Jason") and would return me the index where "Jason" is.

But what if in my case I want to know the index where the "xxxxx" userID is? I tried the following line, but Xcode doesn't like it:

var adminIndex = listOfParticipants.indexOf(ParticipantInfo.participantUser: "xxxxx")

Thanks!

Victor Rius
  • 4,566
  • 1
  • 20
  • 28
  • 1
    In the duplicate question, see the `indexOf` variant that takes a closure as an argument. Something like `listOfParticipants.indexOf({ $0.participantUser == "xxxxx"})` should do the trick. – Sulthan Feb 26 '16 at 19:20
  • Sorry, I've seen all the answers in the linked post but the right one for my case. Now I found it. Thank you – Victor Rius Feb 26 '16 at 19:25

0 Answers0