             cell.sampleImage.image = UIImage(named: data[indexPath.item]["Image"]!)
             cell.sampleLabelText.text = data[indexPath.item]["Name"]
             cell.backgroundColor = nil
-            
+            if selectedArray .contains(indexPath){
+                cell.backgroundColor = .blue
+            }
+
             
             return cell
         }
     }
     //customization to perform on item cell when selected
     func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
-       
+        
+        if (selectedArray.count == 4){
+            sampleGallery.deselectItem(at: indexPath, animated: false)
+            
+            let alert = UIAlertController(title: "Whooops!!", message: "Selection reached max limit", preferredStyle: .alert)
+            alert.addAction(UIAlertAction(title: "Back", style: UIAlertActionStyle.default, handler: nil))
+            self.present(alert, animated: true, completion: nil)
+        }
+        else {
         selectedArray.append(indexPath)
         print(selectedArray)
 
         let cell = sampleGallery.cellForItem(at: indexPath)
         cell?.backgroundColor = .blue
+        }
     }
     
     //resume initial state of item cell when deselected
     func collectionView(_ collectionView: UICollectionView, didDeselectItemAt indexPath: IndexPath) {
         print(#function)
-        if currentView == .isInGridView{
-            let cell = sampleGallery.cellForItem(at: indexPath) as? GridCell
-            cell?.backgroundColor = nil
-        }
-        else{
-            let cell = sampleGallery.cellForItem(at: indexPath) as? ListCell
-            cell?.backgroundColor = nil
-        }
+        
+        let cell = sampleGallery.cellForItem(at: indexPath)
+        cell?.backgroundColor = nil
         
         selectedArray.remove(at: selectedArray.index(of: indexPath)!)
         if selectedArray.isEmpty{

    
    //perform deletion of selected element
    @IBAction func deleteButtonAction(_ sender: UIButton) {
            for indexPath in selectedArray.sorted(by: >){
            data.remove(at: indexPath.item)
            sampleGallery.deleteItems(at: [indexPath])
        }

            cell.sampleImage.image = UIImage(named: data[indexPath.item]["Image"]!)
            cell.sampleLabelText.text = data[indexPath.item]["Name"]
            cell.backgroundColor = nil
            if selectedArray .contains(indexPath){
                cell.backgroundColor = .blue
            }


            return cell
            
