How to find index of list item in Swift?

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

    In case somebody has this problem

    Cannot invoke initializer for type 'Int' with an argument list of type '(Array.Index?)'
    

    jsut do this

    extension Int {
        var toInt: Int {
            return self
        }
    }
    

    then

    guard let finalIndex = index?.toInt else {
        return false
    }
    

提交回复
热议问题