Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How has the NSIndexPath initialization changed in Swift3? [closed]

Tags:

ios

swift

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)
        meals.append(meal)
        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?

Thanks,

like image 399
Garry Pettet Avatar asked Jul 14 '16 19:07

Garry Pettet


1 Answers

NSIndexPath has been changed to IndexPath

try IndexPath(row: Int, section: Int)

API Reference : indexpath

Swift 3.0 Developer Preview

like image 187
iOSGeek Avatar answered Oct 31 '22 19:10

iOSGeek