Aprove answer
  1. You should not call collectionView.reloadData() inside of collectionView(cellForItemAt:). The reason for this is that collectionView(cellForItemAt:) is ran once for every single cell. So if you have 50 cells, it's being called 50 times. In each one of those 50 times, you're telling it to reload again. So your UICollectionView will infinitely reload as you're calling .reloadData() inside of a function that's triggered by .reloadData()

  2. There is no problem in initializing your UICollectionView before retrieving the data. The problem is that you're not updating the UICollectionView when the data is received, only the variables that store your data.

You have not shown what getVideosNamesAndUsers() looks like, but wherever your code would go when the data is finished downloading, you should implement collectionView.reloadData().

Credit Goes to: stackoverflow.com

Related question with same questions but different answers