How do I do indexOfObject or a proper containsObject

后端 未结 8 934
说谎
说谎 2020-12-03 03:00

With an array: How do I do indexOfObject or a proper containsObject?

I mean I know I could just bridge the Array to NSArray an

8条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-03 03:50

    If your array elements are objects and you want to find an identical object in that array, you can use this function:

    func findObject(domain: C, value: C.Generator.Element) -> Int? {
        for (index, element) in enumerate(domain) {
            if element === value {
                return index
            }
        }
    
        return nil
    }
    

提交回复
热议问题