How to hide the cell in tableview if json data nil


How to hide the cell collectionview in section if json data is nil. im loading collectionview in a tableview code is belowim showing array of images in collection view i have used third party for horizontalautomatic scroll as third party for collection view

func setCollectionData(_collectionData: [Any]) {
    self.collectionData = _collectionData as NSArray
    collectionViewObj.setContentOffset(CGPoint(x:0,y:0), animated: true)
    for i in 0 ..< collectionData.count {
        self.strings = StringClass()
        self.strings.vehicleImage = (collectionData[i] as AnyObject).value(forKey: "img_name") as? String
        self.strings.vehicleTitle=(collectionData[i] as AnyObject).value(forKey: "p_name") as? String
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int
    if self.collectionData.count >= 4 {
        return 4
    return collectionData.count

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "ProductCollectionViewCustomCell", for: indexPath)as! ProductCollectionViewCustomCell
    strings = modelArray[indexPath.row]
    cell.ProductTitleLabel.text =  strings.vehicleTitle
    let URLBaseString = ""
    let url = URL(string:URLBaseString .appending(strings.vehicleImage!))
    let dataurl = try? Data(contentsOf: url!)
    cell.productImageViewObj.image=UIImage(data: dataurl!)
    return cell

func collectionView(_ collectionView: UICollectionView,layout collectionViewLayout: UICollectionViewLayout,sizeForItemAt indexPath: IndexPath) -> CGSize

override this method and return zero size if the json data is nil else return actual size of cell


remove nil data from array and call collectionView.reloadData()