ios – NSIndexPath和IndexPath在Swift 3.0中

我最近将我的代码转换为Swift 3.0.我的集合视图和表视图数据源方法现在在其方法签名中包含IndexPath而不是NSIndexPath.但是仍然在方法定义中,将IndexPath类型转换为NSIndexPath.即
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
    }

任何人都可以告诉我为什么indexPath被转换为NSIndexPath.

解决方法

没有理由将IndexPath转换为NSIndexPath.
Swift 3覆盖类型IndexPath具有属性
/// 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迁移者并不完美.

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...