How to find index of list item in Swift?

后端 未结 22 1519
离开以前
离开以前 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:43

    In Swift 4/5, use "firstIndex" for find index.

    let index = array.firstIndex{$0 == value}
    

提交回复
热议问题