Swift arrays and contains, how to determine if a collection contains an object or value?

后端 未结 3 1710
暖寄归人
暖寄归人 2020-12-09 15:25

I\'m at it again with swift arrays and containsObject provided by NSArray only!

I bridge the swift array to NSArray to do that contains:

extension Ar         


        
3条回答
  •  無奈伤痛
    2020-12-09 15:40

    Swift 1:

    let array = ["1", "2", "3"]
    let contained = contains(array, "2")
    println(contained ? "yes" : "no")
    

    Swift 2, 3, 4:

    let array = ["1", "2", "3"]
    let contained = array.contains("2")
    print(contained ? "yes" : "no")
    

提交回复
热议问题