Garry Garry - 1 year ago 613
Swift Question

How has the NSIndexPath initialization changed in Swift3?

I'm trying to follow along with Apple's Start Developing iOS Apps (Swift) tutorial and have almost completed it. I have had to amend several parts of the tutorial as I'm using Xcode 8 (which I think uses Swift 3 instead of Swift 2). However, I am running into the following compiler error and I don't know why:

Argument labels (forRow:, inSection) do not match any available overloads

in the following function:

@IBAction func unwindToMealList(sender: UIStoryboardSegue) {

if let sourceViewController = sender.sourceViewController as? MealViewController, meal = sourceViewController.meal {
// Add a new meal
let newIndexPath = NSIndexPath(forRow: meals.count, inSection: 0)
tableView.insertRows(at: newIndexPath, with: .bottom)


I'm guessing that there is a different initialiser for NSIndexPath that's changed in Swift 3 but I can't find it. Am I doing something wrong?


Answer Source

NSIndexPath has been changed to IndexPath

try IndexPath(row: Int, section: Int)

API Reference : indexpath

Swift 3.0 Developer Preview

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download