How to check if an element is in an array

后端 未结 17 1111
囚心锁ツ
囚心锁ツ 2020-11-22 10:24

In Swift, how can I check if an element exists in an array? Xcode does not have any suggestions for contain, include, or has, and a qu

17条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-22 11:10

    As of Swift 2.1 NSArrays have containsObjectthat can be used like so:

    if myArray.containsObject(objectImCheckingFor){
        //myArray has the objectImCheckingFor
    }
    

提交回复
热议问题