Pass data from CollectionView Delegate to another ViewController
<p>I'm beginner on Swift.</p>

<p>I have <code>CollectionView</code> in my <code>UIViewController</code> and I need to pass data when user clicks on <code>CollectionViewCell</code> to another <code>ViewController</code>.
I tried to override <code>prepareForSegue</code> but I notice that it called first then code on <code>didSelectItemAtIndexPath</code>.</p>

<p><strong>My First ViewController Code:</strong></p>

<pre><code>import UIKit

class ViewController: UIViewController {

    ...

    override func viewDidLoad() {
        super.viewDidLoad()
    }
}

extension ViewController : UICollectionViewDataSource,UICollectionViewDelegate{

    func numberOfSectionsInCollectionView(collectionView: UICollectionView) -&gt; Int {
        return 1
    }

    func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -&gt; Int {
        return items.count
    }

    func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -&gt; UICollectionViewCell {
        let cell = collectionView.dequeueReusableCellWithReuseIdentifier("collCell", forIndexPath: indexPath) as! MainCollectionViewCell

        ...
        return cell
    }

    func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {

        itemId = items[indexPath.item].id

        let distinationViewController = DistinationViewController()
        distinationViewController.itemId = itemId
    }   
}
</code></pre>

<p><strong>My Distination view controller code</strong></p>

<pre><code>import UIKit

class DistinationViewController: UIViewController{

    var itemId : String!

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        print(itemId)
    }
}
</code></pre>

<p>The value of <code>itemId</code> in <code>DistinationViewController</code> is nil</p>

<p>Thanks</p>