Swift - UICollectionView needs time to load data after call
<p>I am making a request for some data , and even though I have already minimise the time from the API the <code>UICollectionView</code> needs 5-6 seconds after the data are retrieved. I am using <code>KingFisher</code> to load images on cell , but even without the images the time is the same.The <code>print</code> "Got the products" is presented really fast but then the data are not visible for 4-5 secs.</p>

<p>My code so far :  </p>

<pre><code>func getAllData(_ page:Int = 0) {
        print("Getting Products")
        lastLoadedPage = page
        let query = getQueryFromSentence()
        API.getData(page: page) { (success,data) in
            print("Got the Data")
            if page == 0 {
                self.products.removeAll()
            }
            if success {
                self.products.append(contentsOf: data)
                self.refresh()
        }
    }
func refresh() {
    DispatchQueue.main.async { 
        self.productCollectionView.reloadData()
    }
}

class CustomViewCell: UICollectionViewCell {
    @IBOutlet weak var imageViewHeightLayoutConstraint: NSLayoutConstraint!
    @IBOutlet weak var editButton: UIButton!
    @IBOutlet var favImage: UIImageView!
    @IBAction func editButtonPressed(_ sender: AnyObject) {
        NotificationCenter.default.post(name: Notification.Name(rawValue: "edit"), object: self, userInfo: nil)
    }
    @IBAction func favPressed(_ sender: AnyObject) {
            NotificationCenter.default.post(name: Notification.Name(rawValue: "fav"), object: self, userInfo: nil)
    }
    func configCell(_ product:Product) {
        self.firstImage.kf.indicatorType = .activity

        if let _ = self.fav {
            self.favImage.isUserInteractionEnabled = true
            let tapGesture = UITapGestureRecognizer(target: self, action: #selector(CustomViewCell.favPressed(_:)))
            self.favImage.addGestureRecognizer(tapGesture)
        }
        //Resize up to 0.5 to fit only one line
        self.firstLabel.numberOfLines = 1
        self.firstLabel.minimumScaleFactor = 0.5
        self.firstLabel.adjustsFontSizeToFitWidth = true

        self.firstImage.kf.setImage(with: URL(string: "first")!, placeholder: UIImage(named: "placeholderImage"), options: nil, progressBlock: { receivedSize, totalSize in
            }, completionHandler: nil)
    }
</code></pre>