title: Add data and reload CollectionView after dismiss ImagePicker - Swift - iOS
body: <p>In my app, user can pick an image with imagepicker. After he chose, I want to update my collectionview (or tableview) with the new image.
  But even if the reload funcs are called and the new item is in my list, the UI is not refreshed.</p>
  
  <p>EDIT TO HIGHLIGHT THIS : I simplify code with cancel dismiss instead because the behavior is the same. 
  I know I have to call didFinishWith... but I want to highlight the behavior causing by the dismiss.</p>
  
  <pre><code>var files = [File]() // populate my collectionview or tableview
  
  // ... code
  // ... more code 
  
  func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
  
      self.dismiss(animated: true) {
  
          let newFile = File(name: "test")
          self.files.append(newFile)
  
          DispatchQueue.main.async {
              self.collectionView?.reloadData()
              // self.tableView?.reloadData() has the same behavior 
          }
      }
  }
  </code></pre>
  
  <p>If I print in collectionView-CellForItemAt ... I see that I have my new element in the list, but it's not show on the screen.</p>
  
  <p>I try differents things, but nothing works or seems very dirty to me. Any idea to perform this properly ?</p>
  
  <p>(I already see this topic : <a href="https://stackoverflow.com/questions/34366830/uicollectionview-wont-reloaddata-after-uiimagepickercontroller-dismisses">UICollectionView won&#39;t reloadData() after UIImagePickerController dismisses</a> )</p>
  
  <p>EDIT FOR MORE INFO :</p>
  
  <pre><code>func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -&gt; Int {
  
      return self.files.count
  }
  
  func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -&gt; UICollectionViewCell {
  
          let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "ItemCell", for: indexPath) as! CollectionViewCell
  
          cell.file = self.files[indexPath.row]
          cell.filenameLabel.text = self.files[indexPath.row].name
          // other customization of cell
          print(cell.file.name)
          return cell
      }
  </code></pre>