title: How do I pass information to a new view controller using a segue in swift
body: <p>I'm running into a problem while working on a simple project. This app essentially just displays a collection of images and when I tap one of the images, it is suppose to transition into a new view controller and display the name of the image on a label. </p>
  
  <p>I am new at Swift. Is it something to do with the indexPath that I used in the function to fill the collection view? I tried to see if I could get the indexPath and then pass that into the images array to get the name and send the name in the second view controller but it comes up nil. Any help would be greatly appreciated</p>
  
  <p>This is my CollectionViewController</p>
  
  <pre><code>
      class ImagePickerViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource {
      @IBOutlet var collectionView: UICollectionView!
  
      var images = Data()
  
      func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -&gt; Int {
          return images.images.count
      }
  
      func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -&gt; UICollectionViewCell {
          if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewCell", for: indexPath) as? CollectionViewCell {
              cell.imageView.image = UIImage(named: "\(images.images[indexPath.item])")
              return cell
          }
          return UICollectionViewCell()
      }
  
  
      override func viewDidLoad() {
          super.viewDidLoad()
          collectionView.delegate = self
          collectionView.dataSource = self
      }
  
      override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
          if let dest = segue.destination as? FeedPickerViewController{
              if segue.identifier == "detailViewController_segue"{
                  let cell = sender as! CollectionViewCell
                  let indexPath = self.collectionView.indexPath(for: cell)
                  let imgName = images.images[indexPath!.item]
                  dest.imgName = imgName
              }
          } 
      }
  }
  </code></pre>
  
  <p>This is theViewController that I am segueing to</p>
  
  <pre><code>
  class DetailViewController: UIViewController {
      var imgName: String!
      @IBOutlet var label: UILabel!
  
      override func viewDidLoad() {
          super.viewDidLoad()
          label.text = "Posting Image: \(imgName)"
      }
  }
  </code></pre>
  
  <p>and this is the data class</p>
  
  <pre><code>class Data {
  
      let images = ["bear", "bird", "bridge", 
                    "cabin"]
  }
  </code></pre>