2016-09-22 16 views
15

最近私のコードをSwift 3.0に変換しました。コレクションビューとテーブルビューのデータソースメソッドに、メソッドシグネチャにNSIndexPathの代わりにIndexPathが含まれるようになりました。しかし、メソッド定義の内部では、IndexPathをNSIndexPathに型キャストしています。 indexPathNSIndexPathにキャストタイプである理由、すなわちSwift 3.0のNSIndexPathと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 
    } 

誰も教えてもらえます。

答えて

26

IndexPathNSIndexPathにキャストする理由はありません。 スウィフト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の移行では、完璧な仕事しませんでした。

関連する問題