如何在Swift中将NSIndexPath转换为Int?

Bar*_*tin 5 ios uicollectionview swift

我需要我的单元格的索引UICollectionView.我知道如何得到它,但问题是当我将其转换NSIndexpathInt.这是我的代码.

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

    let cell = sender as! UICollectionViewCell
    let index = self.collectionView!.indexPathForCell(cell)!

    let vc : VideosViewController = segue.destinationViewController as! VideosViewController
    vc.id_category =  self.result_category[index.row as Int]["id"].intvalue
}
Run Code Online (Sandbox Code Playgroud)

Vic*_*ler 9

您不需要转换index.rowInt,Int已经是,请参阅Apple的声明:

var row: Int { get }
Run Code Online (Sandbox Code Playgroud)

在课堂上NSIndexPath.

做吧vc.id_category = self.result_category[index.row]["id"].intvalue.请小心index of out bound数组中的内容.

我希望这对你有帮助.