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
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
}
}