Swift 3.0中的NSIndexPath和IndexPath

我最近把我的代码转换成了Swift 3.0。 我的集合视图和表视图数据源方法现在在它们的方法签名中包含IndexPath而不是NSIndexPath 。 但是在方法定义里面仍然是对NSIndexPathtypes转换IndexPath。 即

 func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { let cell : NNAmenitiesOrFurnishingCollectionViewCell = self.amenitiesOrFurnishingCollectionView.dequeueReusableCell(withReuseIdentifier: "NNAmenitiesOrFurnishingCollectionViewCell", for: indexPath) as! NNAmenitiesOrFurnishingCollectionViewCell cell.facilityImageName = self.facilityArray[(indexPath as NSIndexPath).row].imageName cell.facilityLabelString = self.facilityArray[(indexPath as NSIndexPath).row].labelText return cell } 

任何人都可以告诉我为什么indexPathtypes转换为NSIndexPath

这里没有理由将IndexPathNSIndexPath 。 Swift 3覆盖typesIndexPath具有属性

 /// The section of this index path, when used with `UITableView`. /// /// - precondition: The index path must have exactly two elements. public var section: Int /// The row of this index path, when used with `UITableView`. /// /// - precondition: The index path must have exactly two elements. public var row: Int 

您可以直接访问:

  cell.facilityImageName = self.facilityArray[indexPath.row].imageName cell.facilityLabelString = self.facilityArray[indexPath.row].labelText 

显然,Xcode的迁移者并不是一个完美的工作。