Q:

In cellForItemAt collection view is not updating indexPath by collectionView.reloadData() in swift 3

I actually want to create table with rows and columns and doing this using UICollectionView. Problem is with reloading or updating collectionView to add or delete rows in my table. Columns and hardcoded i-e 4.
This is how i am doing; 

Creating CollectionView from storyboard
After loading page. Hitting route to get data
After fetching data save the fetched data in an array object. 
Update collection view with the size of the array by collectionView.reloadData().

Starting here.
Referring collection view from storyboard to my viewController
@IBOutlet weak var collectionView: UICollectionView!

then in "viewDidLoad".
self.collectionView.delegate = self
self.collectionView.dataSource = self

Now after getting response from server. I am updating my Array from which i get number of rows to create. After that This is how i am reloading collectionView.
DispatchQueue.main.async
        {
            self.collectionView.collectionViewLayout.invalidateLayout()
            self.collectionView.reloadData()
            print("size of the array is(self.portfolioHandler.data.count)")
    }

In my numberOfSections function. i am getting correct number of cells to create. returning as well.
   func numberOfSections(in collectionView: UICollectionView) -> Int {
    var toReturn : Int = 1
    if (self.portfolioHandler != nil) {
        let data : [PortfolioData] = self.portfolioHandler.data!
        print("dataCount : \(data.count)")
        toReturn = data.count + 1
        print("toReturn : \(toReturn)")
    }
    return toReturn
}

With logs i am getting the returned number. it is correct and returning data correctly.
Now in my cellForItem At index function. IndexPath is not updating. it is still 1. the top header i am creating. No Cell beneath it.
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "MyCell", for: indexPath) as! MyCollectionViewCell
    print("section: \(indexPath.section) && row: \(indexPath.row)")

After everything i tried. Nothing helps me to get the correct cells to create in my collectionView.
A trick can work. Only if i give hardcoded value in numberOfSections in start. Then after server response and reloading collectionView it will create those number of cells like 3 or 4 what i hardcoded above. No more then that. 
But i have to create number of cells which i get from server. Dynamic.
I have spent much time on it. Please help me where i am wrong. or how i can resolve this.

A:

After all attempts. I am unable to solve this reload issue of collection view.
But I handle this in my app by this trick
collection view first time make cells correctly. problem is with reloading. So i made my server request in previous View Controller before coming to this View Controller. And sending the response to this View Controller. This way. i have number of cells to made. So it worked.
But as a learner i am looking forward for an answer and real solution to this reload issue problem.
I will appreciate that. Although thanks @ɯɐɹʞ for your comments.

