jonpeter jonpeter - 2 years ago 92
Swift Question

code involving indexPath & NSIndexPath works - but why is it redundant?

I'm getting back to using CloudKit and in the project I'm revisiting, I have a query fetch performed and I am left with an array of CKRecords. I'm setting this array to be displayed via TableController. Anyways, I have this one line of code (which works)... but I am just unsure why I am setting the indexPath as NSIndexPath.

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "dining") as! table1cell
let restaurant: CKRecord = categories[(indexPath as NSIndexPath).row]
cell.Name.text = restaurant.value(forKey: "Name") as? String

return cell

With my other non-CKRecord TableController projects, I know I don't have to set the indexPath to itself, in essence. What am I missing here?

Answer Source

The use of the cast to NSIndexPath is pointless. Simply change the line to:

let restaurant: CKRecord = categories[indexPath.row]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download