How to check if an element is in an array

后端 未结 17 1115
囚心锁ツ
囚心锁ツ 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:06

    Just in case anybody is trying to find if an indexPath is among the selected ones (like in a UICollectionView or UITableView cellForItemAtIndexPath functions):

        var isSelectedItem = false
        if let selectedIndexPaths = collectionView.indexPathsForSelectedItems() as? [NSIndexPath]{
            if contains(selectedIndexPaths, indexPath) {
                isSelectedItem = true
            }
        }
    

提交回复
热议问题