Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
- if let datasource = flavoursDataSource {
- let cell = collectionView.cellForItem(at: indexPath) as! TasteCollectionViewCell
- let flavourGroup = datasource.priorityFlavourGroups[indexPath.section]
- let flavour = flavourGroup.groupFlavours[indexPath.row]
- let selectedFlavours = selectedGroups.flatMap({$0.groupFlavours})
- if selectedFlavours.first(where: ({ $0.flavourName == flavour.flavourName})) != nil {
- selectedGroups.first(where: ({$0.groupName == flavourGroup.groupName}))?.groupFlavours.removeAll(where: {$0.flavourName == flavour.flavourName})
- cell.deSelectCell()
- } else {
- selectedGroups.first(where: ({$0.groupName == flavourGroup.groupName}))?.groupFlavours.insert(flavour, at: 0)
- cell.selectCell()
- }
- tableView.reloadData()
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement