So, I am currently converting a project to Swift 2 using Xcode 7 beta, and currently I am getting an error:
Cannot adjust value of type '[NSIndexPath]?' with type 'Int'
for the following code code:
let indexPath = indexPaths[0] as! NSIndexPath
when trying to pass data to the view controller, when the user selects a cell in the UICollectionView using the prepareForSegue method.
Here is the complete prepareForSegue method. I'm not sure if this is a Swift 2 bug, but it works fine when using Swift 1.1 for iOS 8.4.
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { if segue.identifier == "details" { let vc = segue.destinationViewController as! DetailsViewController let indexPaths = self.collectionView.indexPathsForSelectedItems() let indexPath = indexPaths[0] as! NSIndexPath let selectedItem = items[indexPath.row] vc.selectedItem = selectedItem } }
source share