I have a JSON through which I get list of boards. Can be accessed by self.jsonGame.boards. Now I have to call all these boards and display the content from it.
But the boards are not consistently called. They’ll only show up sometimes.
func fetchBoard(){
    let repo = GameRepository()
    let prefs = UserDefaults.standard
    if self.jsonGame.boards.count > 0 {
        self.sortedBoardArr.reserveCapacity(self.BoardArr.count)
        for board in self.jsonGame.boards{
            DispatchQueue.main.async
            {
                    repo.GetBoardInfo(gameID: self.jsonGame.Id, boardID: board ,  completion : {(response , errorCode ) -> Void in
                        if errorCode == ErrorCode.NoError{
                            DispatchQueue.main.sync {
                                self.BoardArr.append(response)
                                self.sortArr()
                                self.collectionView.reloadData()
                            }
                        }
                    })
            }
        }
    }
}
func sortArr(){
    if self.jsonGame.boards.count == self.BoardArr.count{
        for board in self.jsonGame.boards{
            for boardarr in self.BoardArr{
                if boardarr.id == board{
                    self.sortedBoardArr.append(boardarr)
                }
            }
        }
    }
}
If anyone can help me figure out how to make sure the boards are called with a consistency.
I'm noob at async handling. Sorry for the trouble.
 
     
    