2016-09-22 5 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으로 변환 할 이유가 없습니다.

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

은 분명히 엑스 코드 Migrator를 완벽한 작업하지 않았다 : 스위프트 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 

있습니다.

관련 문제