Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios Swift 3.0中的NSIndexPath和IndexPath_Ios_Swift_Uicollectionview_Swift3 - Fatal编程技术网

Ios Swift 3.0中的NSIndexPath和IndexPath

Ios Swift 3.0中的NSIndexPath和IndexPath,ios,swift,uicollectionview,swift3,Ios,Swift,Uicollectionview,Swift3,我最近将代码转换为Swift 3.0。我的集合视图和表视图数据源方法现在在其方法签名中包含indepath,而不是nsindepath。但仍然在方法定义中,它是将indepath类型转换为nsindepath的。i、 e func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { let ce

我最近将代码转换为Swift 3.0。我的集合视图和表视图数据源方法现在在其方法签名中包含
indepath
,而不是
nsindepath
。但仍然在方法定义中,它是将indepath类型转换为nsindepath的。i、 e

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
    }

有谁能告诉我为什么
indepath
被类型转换为
nsindepath
这里没有理由将
indepath
转换为
nsindepath
。 Swift 3覆盖类型
indepath
具有属性

/// 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 migrator的工作并不完美。

转换的原因是,如果要将IndexPath发送到需要NSIndexPath作为参数的函数,或者至少需要在Swift 4中这样做。