title: perform segue from collection view
body: <p>My aim is to perform segue from collection view cells to view controller. In the next view controller I have statement</p>
  
  <pre><code> let selectedCar = CarViewController()
  
   if selectedCar.selectedMaker == "a"
  </code></pre>
  
  <p>I know the way to perform segue with additional class, but do not know how to perform with collection view. I used indexPath with if else statements.
  Segue name is "toModels"</p>
  
  <pre><code>class CarsViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate {
  
  public var selectedMaker = ""
  
  @IBOutlet weak var collectionView: UICollectionView!
  
  let mainMenu = ["a","b"]
  
  override func viewDidLoad() {
      super.viewDidLoad()
  
      collectionView.delegate = self
      collectionView.dataSource = self
  }
  
  public func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -&gt; Int {
      return mainMenu.count
  }
  
  public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -&gt; UICollectionViewCell {
      let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "customCell", for: indexPath) as! CustomCollectionViewCell
  
      cell.imageCell.image = UIImage(named: mainMenu[indexPath.row])
      cell.labelCell.text = mainMenu[indexPath.row].capitalized
  
      return cell
  }
  
  public func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
  
      performSegue(withIdentifier: "toModels", sender: selectedMaker)
  
      if indexPath == [0, 0]
      {
          selectedMaker = "a"
          print("a")
      }
      else if indexPath == [0, 1]
      {
          selectedMaker = "b"
          print("b")
      }
  </code></pre>