How to find index of list item in Swift?

后端 未结 22 1898
离开以前
离开以前 2020-11-22 06:17

I am trying to find an item index by searching a list. Does anybody know how to do that?

I see there is list.StartIndex and <

22条回答
  •  南方客
    南方客 (楼主)
    2020-11-22 06:53

    SWIFT 4

    Let's say you want to store a number from the array called cardButtons into cardNumber, you can do it this way:

    let cardNumber = cardButtons.index(of: sender)
    

    sender is the name of your button

提交回复
热议问题