Ios Swift 3.0中的NSIndexPath和IndexPath
我最近将代码转换为Swift 3.0。我的集合视图和表视图数据源方法现在在其方法签名中包含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
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中这样做。