Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
  2.  
  3. if let datasource = flavoursDataSource {
  4.  
  5. let cell = collectionView.cellForItem(at: indexPath) as! TasteCollectionViewCell
  6.  
  7. let flavourGroup = datasource.priorityFlavourGroups[indexPath.section]
  8. let flavour = flavourGroup.groupFlavours[indexPath.row]
  9.  
  10. let selectedFlavours = selectedGroups.flatMap({$0.groupFlavours})
  11.  
  12. if selectedFlavours.first(where: ({ $0.flavourName == flavour.flavourName})) != nil {
  13. selectedGroups.first(where: ({$0.groupName == flavourGroup.groupName}))?.groupFlavours.removeAll(where: {$0.flavourName == flavour.flavourName})
  14. cell.deSelectCell()
  15. } else {
  16. selectedGroups.first(where: ({$0.groupName == flavourGroup.groupName}))?.groupFlavours.insert(flavour, at: 0)
  17. cell.selectCell()
  18. }
  19. tableView.reloadData()
  20. }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement