UICollectionView gets the wrong index
<p>My collectionview gets one different index each time its tapped. Thats the code i have implemented: </p>

<p>override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {</p>

<pre><code>if (segue.identifier == "projectsSegue") {
    let indexPath = collectionView.indexPathForCell(sender as! MyCell)
    let indexPathItem = indexPath?.item


    let controller = (segue.destinationViewController ) as! ProjectsByCodeViewController


    controller.indexSelected = indexPathItem!


}
</code></pre>

<p>I do think that all should works correctly, but it does not. What do I need to do? My array has 4 items, and if im on the last one, it detects as the 3rd, and if im on the 1st it detects as the 1st, not the 0 index. And if I start from the end it says index 1. What's wrong?</p>