Check if array contains part of a string in Swift?

前端 未结 9 1099
无人共我
无人共我 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:21

    In Swift 5 with better readability :

    let itemsArray = ["Google", "Goodbye", "Go", "Hello"]
    let searchString = "Googled"
    
    let result = itemsArray.contains(where: searchString.contains)
    print(result) //prints true in the above case.
    

提交回复
热议问题