I have recently converted my code to Swift 3.0. My collection view and table view data source methods now contain IndexPath
instead of NSIndexPath
in their method signature. But still inside the method definition it is type casting IndexPath to NSIndexPath. 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
}
Can anyone tell me why indexPath
is type casted to NSIndexPath
.
There is no reason to cast
IndexPath
toNSIndexPath
here. The Swift 3 overlay typeIndexPath
has propertieswhich you can access directly:
Apparently the Xcode migrator did not a perfect job.