Skip to content

Instantly share code, notes, and snippets.

@dilipiOSDeveloper
Last active September 13, 2018 09:42
Show Gist options
  • Save dilipiOSDeveloper/c12cb8778feb0d66d0c8122a80963845 to your computer and use it in GitHub Desktop.
Save dilipiOSDeveloper/c12cb8778feb0d66d0c8122a80963845 to your computer and use it in GitHub Desktop.
Code for checking Selected or Unselected state of CollectionView or TableView
// Code for checking when cell is selected for CollectionView
let cell = collectionView.cellForItem(at: indexPath)
if cell?.isSelected == true{
// cell is selected
}
else{
// cell is not selected
}
// Code for checking when cell is selected for TableView
let cell = catListTable.cellForRow(at: indexPath)
if cell?.isSelected == true{
// cell is selected
}
else{
// cell is not selected
}
// Filter array of strings
import Foundation
let arr = ["anuj","amit","tripathi"]
let filtered = arr.filter { $0.contains("i") }
print(filtered) // Output :- ["amit", "tripathi"] // if we take capital "i" then it will print empty array like []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment