Check if array contains part of a string in Swift?

前端 未结 9 1082
无人共我
无人共我 2020-12-08 15:04

I have an array containing a number of strings. I have used contains() (see below) to check if a certain string exists in the array however I would like to chec

9条回答
  •  爱一瞬间的悲伤
    2020-12-08 15:14

    If you are just checking if an item exists in a specific array, try this:

    var a = [1,2,3,4,5]
    
    if a.contains(4) {
        print("Yes, it does contain number 4")
    }
    else {
        print("No, it doesn't")
    }
    

提交回复
热议问题