title: blank collection view in user login for the first time
body: <p>Good day everyone,</p>
  <p>I have root view controller set up as my <strong>HomeViewController</strong>, in this project i am using token based authentication ( which i am storing in user defaults ) and i am using token for all my API calls.</p>
  <p>I have a check in my <strong>viewWillAppear</strong> method to check if there is access token present and then  i make the api call in <strong>viewDidAppear</strong> to populate the collection view, and this works perfectly fine at all times except the first time.</p>
  <p>If I log in for the first time it hits the viewWillAppear, viewDidAppear and then login screen pops up and once i authenticate the user and save it in the UserDefaults, dismiss the login screen and in the HomeViewController all i get is a spinner ( which means that <strong>viewDidAppear</strong> is also been called )  but if i close the app and open it again it all works fine.</p>
  <p>What can i change in my code to make it work in the first time please and thank you!!</p>
  <pre><code>class HomeViewController: UIViewController {
          
      // MARK: - Properties
          
      let refreshControl = UIRefreshControl()            
      var publishedReportList: [ReportListDetail] = []
      
      private let reportsCollectionView: UICollectionView = {
          let viewLayout = UICollectionViewFlowLayout()
          let collectionView = UICollectionView(frame: .zero, collectionViewLayout: viewLayout)
          collectionView.register(ReportsCollectionViewCell.self, forCellWithReuseIdentifier: ReportsCollectionViewCell.identifier)
          collectionView.backgroundColor = .systemBackground
          return collectionView
      }()
      
      // MARK: - Initialisation
      override func viewDidLoad() {
          super.viewDidLoad()
                  
          reportsCollectionView.delegate = self
          reportsCollectionView.dataSource = self
  
          print(publishedReportList.count)
                  
          refreshControl.tintColor = .blue
          refreshControl.addTarget(self, action: #selector(pullToRefresh), for: .valueChanged)
          reportsCollectionView.addSubview(refreshControl)
          reportsCollectionView.alwaysBounceVertical = true
      }
      
  override func viewWillAppear(_ animated: Bool) {
          super.viewWillAppear(animated)        
          // check auth status
          handleNotAuthenticated()
      }
      
      override func viewDidAppear(_ animated: Bool) {
          // call for reports
          getReportUserLayout()
      }
      
      // MARK: - Handlers
      
      @objc func pullToRefresh() {
         // Code to refresh table view
          getReportUserLayout()
      }
      
      fileprivate func getReportUserLayout() {
  //        publishedReportList.removeAll()
          whySuchEmptyLabel.isHidden = true
          spinner.show(in: view)
          spinner.textLabel.text = &quot;Loading Reports..&quot;
          DispatchQueue.main.async {
              ReportsManager.shared.getReportData { [weak self] (listOfReports) in
                  
                  guard let strongSelf = self else { return }
                  strongSelf.publishedReportList = listOfReports
                  if listOfReports.count == 0 {
                      strongSelf.whySuchEmptyLabel.isHidden = false
                  }
                  strongSelf.reportsCollectionView.reloadData()
                  strongSelf.spinner.dismiss()
                  strongSelf.refreshControl.endRefreshing()
              }
          }
      }
      
      private func handleNotAuthenticated() {
          
          if UserDefaults.standard.string(forKey: &quot;accessToken&quot;) == nil {
              // show login view controller
              let loginVC = LoginViewController()
              loginVC.modalPresentationStyle = .overCurrentContext
              present(loginVC, animated: false)
          }
      }
  }
  </code></pre>