Così sto attualmente conversione di un progetto di Swift 2 utilizzando Xcode 7 beta, e attualmente sto ottenendo l'errore:Non può indicizzare un valore di tipo '[NSIndexPath]' con un tipo Int
Cannot subscript a value of type '[NSIndexPath]?' with a type 'Int'
per il seguente ling di codice:
let indexPath = indexPaths[0] as! NSIndexPath
quando si tenta di passare dati a un controllore vista quando un utente seleziona una cella in UICollectionView
utilizzando prepareForSegue
metodo.
Ecco il metodo prepareForSegue
completo. Non sono sicuro che si tratti di un errore di Swift 2, ma funziona correttamente quando si utilizza Swift 1.1 per 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
}
}
Prova a fare 'lasciare indexPaths = self.collectionView.indexPathsForSelectedItems() come! [NSIndexPath] ' –
@TheBeanstalk yeah questo sembrava fare il trucco per ora, convertendo ancora codice e incapace di eseguire atm. 'let indexPaths = self.collectionView.indexPathsForSelectedItems() come [NSIndexPath]!' – RileyDev
Potrebbe anche funzionare se si lascia la riga 'indexPaths' da solo, e invece di fare' allow indexPath = indexPaths! [0] as! NSIndexPath' –